Thursday, January 16, 2014

Liferay: Custom 404 Page for plugins

Liferay portal runs and is configured as ROOT application with in tomcat sever.
By default, if tried to request a plugin in Liferay (say we have a theme plugin named as "error-theme"), a 404 Error is raised and the user is served Tomcat's default 404 error page as below:


To make your 404 page a bit more presentable, provide the user with a link back into your site, as well as hide the Tomcat version in use, you can easily add a custom 404 error page.

Step 1:

Create a jsp name it 404.jsp, with below content:


The requested resource is not available. Please provide the correct URL or try again later.
<br/>
<a href="#" onclick="javascript:history.go(-1);">Go back to main site.</a>

Step 2:

Now create a new directory as error-theme/docroot/errors in Lifeay IDE and copy the above created 404.jsp to it.

Step 3:

Last step is to add the below code to the web deployment descriptor (web.xml) of the plugin:

         <error-page>
  <error-code>404</error-code>
  <location>/errors/404.jsp</location>
 </error-page>

Now, when someone goes to the plugin link that does not exist, they get the custom 404 page we created.





4 comments:

  1. Where to create this error-theme/docroot/errors folder?? be specific

    ReplyDelete
  2. error-theme as the name suggests is Liferay Theme plugin.

    ReplyDelete
  3. Hi Rishi,

    I added an entry in web.xml :

    404
    /errors/404.jsp


    And created a 404.jsp page but its not working. It does not give any exception even and redirects to the same default jsp of liferay which says

    "Not Found
    The requested resource was not found.
    http://localhost:8080/web/websitename/homes"

    Can you please suggest?

    Thanks
    Rahul Saraswat

    ReplyDelete
  4. @rahil did you find a fix for your problem ?

    ReplyDelete