This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:include when the html to be included is not present

 
Sudarshan Chakrabarty
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a jsp page which has a jsp:include to include a html page.
When the html page is not present I get a 404 Page not found error.
Is there a way where I can display my own error page instead of the 404 - Page not found page?

- Sudarshan
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The servlet spec provides a mechanism that allows you to assign your own pages by error type. There is a link in my signature.
Search for "error-page" and you will find the section quickly.

As for included pages.
I wouldn't consider it a normal issue to have pages with broken include directives and I'm not sure how the error-page mechanism handles this. You'll have to play around with it and see.
 
Sudarshan Chakrabarty
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Configuring the web.xml to add the following entry seems to help.

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


Any other suggestions would be helpful.
 
Bosun Bello
Ranch Hand
Posts: 1510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What other suggestions do you need besides what Ben already said. Having a jsp with includes that reference missing files is an error. The container displays your configured error page when it occurs. bottom line is to avoid the error. So do not try to include or forward to resources that do not exist.

Originally posted by Sudarshan Chakrabarty:
Configuring the web.xml to add the following entry seems to help.

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


Any other suggestions would be helpful.
 
Sudarshan Chakrabarty
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben/Bosun,

Thanks for your insight.
I appreciate your concern, but unfortunately the application is such that sometimes the included file might not be present and so we need to show our custom error page. Not the best of designs I am afraid but that's how the application has been designed long back :-(.

I will definitely try to push for a redesign, but till then I needed a solution :-(.. Thanks again.
- Sudarshan
 
Sudarshan Chakrabarty
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh forgot to mention...

Adding the following web.xml entry doesn't seem to help :-(.

****************************************************
<error-page>
<error-code>404</error-code>
<location>/jsp/error_404.jsp</location>
</error-page>
*********************************************************

Apparently,if the page is missing when we do a jsp:include, then it doesn't get registered as an error or exception, so it is not being identified as a 404 error. Hence, the error.jsp is not displayed :-(.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think there is anything in the JSP or servlet spec for handling missing includes gracefully.

What's going on with your environment that would cause includes to be unreliable?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic