aspose file tools*
The moose likes Struts and the fly likes doubt in error handling in web.xml file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "doubt in error handling in web.xml file" Watch "doubt in error handling in web.xml file" New topic
Author

doubt in error handling in web.xml file

raja ram
Ranch Hand

Joined: Mar 02, 2008
Posts: 169
Hi,

we have <error-page> atribute in web.xml file in file i have set up
<error-page>
<error-code>404></error-code>
<location>/pagenot found.jsp</location>
</error-page>

it works fine for when i get 404 error it directs me to this jsp.but i have one problem in the web.xml i have mapping like this

<servlet>
<servlet-name>action</servlet>
<servlet-class>org.apache.struts.ActionServlet</servlet-class>
<servlet>

<servlet-mapping>
<servlet-name>action</servlet>
<servlet-class>*.jhtml</servlet-class>
<servlet-mapping>

in my browser when i call /i.jhtml where the file i.jhtml is not actually present it should display page not found.jsp file instead of this it displays a blank page on the browser. how can i solve this problem.

i think it is able to find valid mapping in *.jhtml web.xml specified above because of this reason it is displaying blank page instead of pagenotfound.jsp but if say like i.jtml then it displays pagenotfound.jsp but i want this page to be displayed even when i call i.jhtml wher the file i.jhtml is not existing. can any body help me in solving this issue.

Thanks
[ March 02, 2008: Message edited by: raja ram ]
Collins Mbianda
Ranch Hand

Joined: Aug 11, 2007
Posts: 259
Hi raja !!!

You are using the Struts framework.
In your webapp, all the requests with the extension ".jhtml" will be managed
by the struts's Controller (org.apache.struts.ActionServlet).

That Servlet looks for valid mappings not in web.xml, but in a file generally called struts-config.xml
If the mapping is not in the config'file, you will have a blank page.

When you are using Struts, the <error-page> won't get processed.
You need to specify the error page redirection in struts-config.xml
You can put it in <global-exceptions> in struts-config.xml
You could configure it for java.lang.Exception. The 404 - Page not found would also be handled.

Make sure your config'file configured in web.xml :

<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>


Hope it help.


SCJP 5.0 | SCWCD 1.4
raja ram
Ranch Hand

Joined: Mar 02, 2008
Posts: 169
Hi,

Thanks for the reply can any one please let me know how to use <global-exceptions> in struts-config.xml with some example code

Thanks
Anubhav Anand
Ranch Hand

Joined: May 18, 2007
Posts: 341

Originally posted by raja ram:
Hi,

Thanks for the reply can any one please let me know how to use <global-exceptions> in struts-config.xml with some example code

Thanks


In struts-config.xml, we declare <global-exceptions> in the following format:



Here we are declaring that any Action (or business logic) that throws the SystemException will be sent to systemError.jsp. We are associating the error.system.crash message string from our SystemResource file with this exception.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt in error handling in web.xml file