RE: How to configure a custom page for JSP 404 errors?
Hello, I have found a workaround for this problem. You *can* configure Tomcat 3.2.2 to go to a particular page in the case of a 404 (or other error), with this tag: 404 /CustomDefault But, the has to be a *servlet*. JSP or HTML pages won't work. Also make sure you register both a and a like this: CustomDefault yourPackage.CustomDefault -2147483646 CustomDefault /CustomDefault If you would like to be a JSP or HTML page, the workaround is this: Make your default servlet redirect to your JSP or HTML page. (For some reason a server-side forward or include doesn't work either). So, if you want to go to your own "error.jsp" in the case of 404 errors, the CustomDefault servlet would look something like this: -- import java.io.IOException; import javax.servlet.*; import javax.servlet.http.*; public class CustomDefault extends HttpServlet { public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.sendRedirect("/error.jsp"); } } -- I hope this helps anyone dealing with this problem. Pierce Courtney [EMAIL PROTECTED] -----Original Message- From: Courtney, Pierce Sent: Monday, July 09, 2001 3:38 PM To: '[EMAIL PROTECTED]' Subject: RE: How to configure a custom page for JSP 404 errors? Ryan and Hunor (Hades), Thanks for your replies, but this simply does not work for me (perhaps I'm missing something... some other setting one must set in server.xml or something?) I created a simple error.jsp and put this snippet in the main web.xml in /conf/ and also in the web.xml file for my specific webapp: 404 /error.jsp I also set the isErrorPage tag in my error.jsp per Hunor's suggestion. Also I searched harder through the Tomcat User archives, and there seem to be many people who have tried and failed to use this feature. But I could find no mention of anyone actually having used this feature... I'm getting the impression that this feature is buggy or not implemented. BTW, This feature works perfectly in Tomcat 4.0-b5. If anyone has actually gotten this to work on Tomcat 3.2.2, please let me know how you did it. Thanks in advance, -Pierce Courtney [EMAIL PROTECTED] -Original Message- From: Hunor Nam [mailto:[EMAIL PROTECTED]] Sent: Monday, July 09, 2001 12:43 AM To: [EMAIL PROTECTED] Subject: RE: How to configure a custom page for JSP 404 errors? You also MUST set in your "error page" the faloving tag: <%@ page isErrorPage="true" %> Hades -Original Message- From: Ryan Lubke [mailto:[EMAIL PROTECTED]] Sent: Friday, July 06, 2001 10:29 PM To: [EMAIL PROTECTED] Subject: Re: How to configure a custom page for JSP 404 errors? Hi Pierce, From what I've been able to gather, you should be able to set the error page using the directive within the deployment descriptor for a web app (web.xml). 404 /error.jsp Looking through the bug database, there was an open issue regarding the use of static html pages within the tag. I'm uncertain at this time what release it's actually fixed in, but if you try it and get a stacktrace, then I guess you know :) The bug report can be found here: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=291 I did find this information in the archives. Try looking at the results of the following search: http://mikal.org/interests/java/tomcat/archive/search?search=error+page+ custom+404 I'm sure those who are more experiences could expand/correct on this information. Hope this helps. -rl Courtney, Pierce wrote: >Hello, > >This question probably has come up before, I just can't find it in the >archives > >I am using Tomcat 3.2.2 standalone (not with Apache). > >How can I configure a particular page (servlet, static html, or jsp) to be >the "default" >page that comes up if the requested jsp is not found, instead of the 404 >error. >In other words, if a user requests: >http://myTomcatSite.com/somePage.jsp > >I want to have somePage.jsp come up if it exists. >But if somePage.jsp does not exist, I *don't* want the default 404 error to >be displayed. Instead I want some custom page (a servlet actually) to be >processed. I don't really care if this is achieved with a client-side >redirect or a server-side include/forward. > >I have tried using the DefaultServlet, which doesn't seem to work. I have >also set up my own servlet against /* . This >works for servlets only, not JSPs. It seems the basic problem is that any >URI that matches *.jsp. gets processed by the JspServlet
RE: How to configure a custom page for JSP 404 errors?
Ryan and Hunor (Hades), Thanks for your replies, but this simply does not work for me (perhaps I'm missing something... some other setting one must set in server.xml or something?) I created a simple error.jsp and put this snippet in the main web.xml in /conf/ and also in the web.xml file for my specific webapp: 404 /error.jsp I also set the isErrorPage tag in my error.jsp per Hunor's suggestion. Also I searched harder through the Tomcat User archives, and there seem to be many people who have tried and failed to use this feature. But I could find no mention of anyone actually having used this feature... I'm getting the impression that this feature is buggy or not implemented. BTW, This feature works perfectly in Tomcat 4.0-b5. If anyone has actually gotten this to work on Tomcat 3.2.2, please let me know how you did it. Thanks in advance, -Pierce Courtney [EMAIL PROTECTED] -Original Message- From: Hunor Nam [mailto:[EMAIL PROTECTED]] Sent: Monday, July 09, 2001 12:43 AM To: [EMAIL PROTECTED] Subject: RE: How to configure a custom page for JSP 404 errors? You also MUST set in your "error page" the faloving tag: <%@ page isErrorPage="true" %> Hades -Original Message- From: Ryan Lubke [mailto:[EMAIL PROTECTED]] Sent: Friday, July 06, 2001 10:29 PM To: [EMAIL PROTECTED] Subject: Re: How to configure a custom page for JSP 404 errors? Hi Pierce, From what I've been able to gather, you should be able to set the error page using the directive within the deployment descriptor for a web app (web.xml). 404 /error.jsp Looking through the bug database, there was an open issue regarding the use of static html pages within the tag. I'm uncertain at this time what release it's actually fixed in, but if you try it and get a stacktrace, then I guess you know :) The bug report can be found here: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=291 I did find this information in the archives. Try looking at the results of the following search: http://mikal.org/interests/java/tomcat/archive/search?search=error+page+ custom+404 I'm sure those who are more experiences could expand/correct on this information. Hope this helps. -rl Courtney, Pierce wrote: >Hello, > >This question probably has come up before, I just can't find it in the >archives > >I am using Tomcat 3.2.2 standalone (not with Apache). > >How can I configure a particular page (servlet, static html, or jsp) to be >the "default" >page that comes up if the requested jsp is not found, instead of the 404 >error. >In other words, if a user requests: >http://myTomcatSite.com/somePage.jsp > >I want to have somePage.jsp come up if it exists. >But if somePage.jsp does not exist, I *don't* want the default 404 error to >be displayed. Instead I want some custom page (a servlet actually) to be >processed. I don't really care if this is achieved with a client-side >redirect or a server-side include/forward. > >I have tried using the DefaultServlet, which doesn't seem to work. I have >also set up my own servlet against /* . This >works for servlets only, not JSPs. It seems the basic problem is that any >URI that matches *.jsp. gets processed by the JspServlet. So it is not >determined if the .jsp file actually exists or not until the JspServlet is >triggered. > >Can this custom error page functionality be configured somehow in Tomcat? > >Thanks for any help, >Pierce Courtney >[EMAIL PROTECTED] > >
How to configure a custom page for JSP 404 errors?
Hello, This question probably has come up before, I just can't find it in the archives I am using Tomcat 3.2.2 standalone (not with Apache). How can I configure a particular page (servlet, static html, or jsp) to be the "default" page that comes up if the requested jsp is not found, instead of the 404 error. In other words, if a user requests: http://myTomcatSite.com/somePage.jsp I want to have somePage.jsp come up if it exists. But if somePage.jsp does not exist, I *don't* want the default 404 error to be displayed. Instead I want some custom page (a servlet actually) to be processed. I don't really care if this is achieved with a client-side redirect or a server-side include/forward. I have tried using the DefaultServlet, which doesn't seem to work. I have also set up my own servlet against /* . This works for servlets only, not JSPs. It seems the basic problem is that any URI that matches *.jsp. gets processed by the JspServlet. So it is not determined if the .jsp file actually exists or not until the JspServlet is triggered. Can this custom error page functionality be configured somehow in Tomcat? Thanks for any help, Pierce Courtney [EMAIL PROTECTED]