Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to handle 404 ,500 errors using structs2.1 using tiles

807580May 29 2010 — edited May 29 2010
Hi,
Can you please any body help me on this : Handle errors 404 and 500 errors using struts2.1 using tiles

Below is my code:
web.xml
-----------
<welcome-file-list>
<welcome-file>/jsp/index.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>404</error-code>
<location>/404</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/500</location>
</error-page>

error.xml
--------------
<struts>
<package name="error" extends="default">
<action name="404" class="com.votingcentral.actions.errors.ErrorAction" method="show">
<result name="success" type="tiles" >error.404</result>
</action>
<action name="500" class="com.votingcentral.actions.errors.ErrorAction" method="show">
<result name="success" type="tiles" >error.500</result>
</action>

</package>
</struts>

ErrorAction.java
---------------------
public class ErrorAction {

public String show() throws Exception {
return SUCCESS;
}
}

tiles.xml
-------------
<definition name="vcErrorTemplate"
template="/jsp/tiles2/vcErrorTemplate.jsp">
<put-attribute name="title" value="Welcome to VotingCentral. Your vote can be the difference!!" />
<put-attribute name="metakeywords" value=".metakeywords" />
<put-attribute name="header" value=".header" />
<put-attribute name="search" value=".bigsearch" />
<put-attribute name="footer" value=".footer" />
</definition>
<definition name="error.404" extends="vcErrorTemplate">
<put-attribute name="title" value="VotingCentral Page not Found" />
<put-attribute name="pageContent" value="/jsp/errors/404.jsp" />
</definition>
<definition name="error.500" extends="vcErrorTemplate">
<put-attribute name="title" value="VotingCentral Unexpected Error" />
<put-attribute name="pageContent" value="/jsp/errors/500.jsp" />
</definition>

vcErrorTemplate.jsp
----------------------------

---- some code .....

<td width="990" bgcolor="#ffffff">
<!-- Begin: Body Left, Main, Right -->
<tiles:insertAttribute name='pageContent'/>
<!-- End: Body Left, Main, Right -->
</td>


404.jsp
-----------

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags" %>

<div style="padding:0px 0px 0px 3px">
<table border="0" cellpadding="0" cellspacing="1" width="100%" class="lightbluebg">
<tr>
<td valign="middle" bgcolor="#FFFFFF">
<div id="blueTitle">Page not found error</div>
<div id="bulletBox">


</div>
</td>
</tr>
</table>
</div>


Regards,
Madhu
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 26 2010
Added on May 29 2010
1 comment
1,027 views