Jboss custom error page

JBoss 7 or eap 6.x default 404 error configurations when your application is down.


Do you want to display custom 404 error page when application is itself is down rather than default 404 error page by Jboss?

                                   From this ?




                                    to this?



then do this,


1. locate standalone.xml or domain.xml if clustered, find and edit enable-welcome-root under <virtual-server> , set value to false

                <virtual-server name="default-host" enable-welcome-root="false">
                    <alias name="localhost"/>
                </virtual-server>

2. restart server , now accessing your app will show blank page.

3. Create a new 'DefaultError' web application, in your favourite IDE
4. In web.xml, add
                  <error-page>
                             <error-code>404</error-code>
                             <location>/error.jsp</location>
                 </error-page>

5. Design your error.jsp accordingly , as shown in above pic and place it in your web application. Location depends on your need and update the location in web.xml accordingly.

example

<html>
<body>
<%
String serverPath = "http://"+request.getLocalAddr()+":"+ request.getLocalPort()+"/";
%>
<div style="position: absolute;top:30%;right:30%;" >
<table>
<tr><td>&nbsp;</td>
<td><img  src="<%=serverPath %>Companylogo.png"></td></tr>
<tr><td><img src="<%=serverPath %>person.jpg"></td><td>
<td style="color:grey;font-size: 16;font-family: verdana;" >We are sorry for inconvenience, app is temporarily unavailable. We are currently working to fix the problem. Please try after sometime.
Thank you.
</td>
</tr>
</table>
</div>
</body>
</html>

you can even add welcome page, add it in welcome page list in web.xml.

6. Add jboss-web.xml under WEB-INF, having context root has '/'

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee 
                                    http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">


   <context-root>/</context-root>
      
</jboss-web> 

7. Now export your DefaultError web application as war and deploy using jboss console.
    For clustered deployment, make sure you deploy to server-group.
    Default console URL would be http://localhost:9990/console


8. Once successfully deployed , you can test accessing your MyApp application, now it should show your custom error page.















_











Comments