• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

404 prob.

 
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am new to struts.

Please help me implement the 404 error page handling in struts.

(like we can specify in web.xml for error-code for servlets/jsp.)

Regards,
Neeraj.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since Struts is only a particular way of creating a J2EE web application, you can intercept the 404 error in exactly the same way that you would in any other J2EE web application. There is no difference for a Struts application.
 
Neeraj Vij
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

It is not reaching the error page in case of struts.
when I am testing it on a normal application. it reaching there.

I tried by using

<global-exceptions>
<exception key="errors.cancel" type="java.lang.Exception" path="/WEB-INF/jsp/error/ErrorPage.jsp"/>
</global-exceptions>

in my struts-config.xml file. still not working.


Regards,
Neeraj.
 
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try and see if global forward helps...

<global-forwards>
<forward name="error" path="/<your_context_root>/error.jsp"/>
</global-forwards>
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I added the following to the web.xml file for my Struts application:



When I submit the url

www.mycompany.com/myApp/nonExistentPage.jsp

The error.jsp page is displayed.

There is nothing unique to Struts about this. It's how you would redirect an HTTP error in any J2EE web application using servlet 2.2 and above.
[ March 09, 2006: Message edited by: Merrill Higginson ]
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a little more complicated than I originally thought. While the method used in my previous post will work if the URL is xyz.jsp, or xyz.htm, it will not work for xyz.do if xyz is not a valid action path.

The reason for this is that I've specified in my web.xml file that the Struts action servlet is to get called for any URI ending in .do. So, for any requests ending in .do, the struts ActionServlet takes over, and when it doesn't find an Action path, it sends a 404 error back to the browser.

If you want to change this behavior you will have to override the processMapping() method in the org.apache.struts.action.RequestProcessor class.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic