How To create a customized "Access Denied" landing page with Spring 3 and Tiles 3

fievelk · July 30, 2013

Your new site finally needs the last thouch. You’re wasting your time walking back and forth in your room trying to think about what to do to improve it: suddenly, you remember that time when you first saw a customized landing page for that (otherwise) annoying 403 error.

Now the question is: how the hell can I do that?

And here’s the answer!

(Yes, that was an absolutely boring post introduction, but I’m not a writer. Not yet, at least.)

Error 403
Photo Credit: Unknown

The steps!

  1. In security-config.xml

     <security:access-denied-handler error-page="/accessdenied">
    
  2. In webmvc-config.xml

     <mvc:view-controller path="/accessdenied" view-name="common.accessdenied">
     </mvc:view-controller>
    
  3. In tiles-defs.xml (your tiles definitions file) define the tile for your landing page

     <definition extends="template" name="errors.denied">
         <put-attribute name="content" value="/WEB-INF/views/denied.jsp">
     </put-attribute></definition>
    

    Obviously, change the paths consequently to your denied.jsp location.

You’re done!

Now, you just have to customize the jsp in order to show the contents you want.

Twitter, Facebook