aspose file tools*
The moose likes JSP and the fly likes jsp:include when the html to be included is not present Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp:include when the html to be included is not present" Watch "jsp:include when the html to be included is not present" New topic
Author

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

Sudarshan Chakrabarty
Ranch Hand

Joined: Apr 10, 2008
Posts: 38
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

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Sudarshan Chakrabarty
Ranch Hand

Joined: Apr 10, 2008
Posts: 38
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

Joined: Nov 06, 2000
Posts: 1510
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.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Sudarshan Chakrabarty
Ranch Hand

Joined: Apr 10, 2008
Posts: 38
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

Joined: Apr 10, 2008
Posts: 38
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

Joined: Dec 11, 2004
Posts: 13410

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
 
subject: jsp:include when the html to be included is not present