You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Pankaj Bhagat <pb...@reef.com> on 2000/12/12 11:17:30 UTC

Custom error pages!!

Hi ppl:
I had posted a very simple query..........but had not received any comments. So am i the only unlucky person who's stuck on this simple problem. Any suggestions are welcome plz.

I want Custom error pages, in my application, the two solutions i have is to use the "ErrorDocument" directive in Apache or to use the "error-pages" xml element while deploying my servlet in Tomcat (please note that i am using Apache 1.3 and Tomcat 3.2). But somehow both of them are not responding to the changes i try to make. Am only getting some satisfaction if i try and call a page which does not exist through Apache (with netscape.......IE.......still does nothing).

Hoping to get some replies this time.

Regards
Pankaj

Re: Custom error pages!!

Posted by Kief Morris <ki...@bitBull.com>.
Catherine Jung typed the following on 16:18 12/12/2000 +0000
>Boy mailing lists have a short memory!, I'd been having trouble with this
>last week and posted about it, on tomcat-dev too, but to no avail. 
>
>No-one seems to check the archives/bug database these days.... :)

Actually I did look, but I didn't see it in there. Actually, I don't find my own 
when I search for it either, although it's in the database.

If I get the time I'll look at fixing it myself: I found the place in the source
where it's happening, but I don't understand the context well enough yet
to fix it.

Kief

---
              bitBull makes the Internet bite: http://www.bitBull.com/demos/


Re: Custom error pages!!

Posted by Catherine Jung <ca...@netcentricsystems.net>.
Hiya, 

No problem, if you go to the Tomcat site:

jakarta.apache.org/tomcat/index.html

it has links to both the bug report/search site:

http://znutar.cortexity.com/BugRatViewer/

and the searchable mailing list archives:

http://mikal.org/interests/java/tomcat/index.html

Hope it helps,

Catherine

> I'm new to this mailing-list and reviewing the WELCOME notice, I found no
> trace related to the database you're refering to. Can you please provide me
> with the directions?

> Thanks in advance,
> Alexandre


Re: Custom error pages!!

Posted by Alexandre Simonin <al...@eurocontrol.fr>.
Catherine,

I'm new to this mailing-list and reviewing the WELCOME notice, I found no
trace related to the database you're refering to. Can you please provide me
with the directions?

Thanks in advance,
Alexandre

Catherine Jung wrote:

> Hiya,
>
> > n cheers.........
> > v have found a bug..........hahahaha
>
> Boy mailing lists have a short memory!, I'd been having trouble with this
> last week and posted about it, on tomcat-dev too, but to no avail.
>
> > so guess a lot of ppl. like us wont have to waste their time on it....
>
> <grin> If my experience is anything to go by, I expect this topic to rear
> it's head again about Monday.....
>
> No-one seems to check the archives/bug database these days.... :)
>
> Catherine.
>


Re: Custom error pages!!

Posted by Catherine Jung <ca...@netcentricsystems.net>.
Hiya,

> n cheers.........
> v have found a bug..........hahahaha

Boy mailing lists have a short memory!, I'd been having trouble with this
last week and posted about it, on tomcat-dev too, but to no avail. 

> so guess a lot of ppl. like us wont have to waste their time on it....

<grin> If my experience is anything to go by, I expect this topic to rear
it's head again about Monday..... 

No-one seems to check the archives/bug database these days.... :)

Catherine.
 


Re: Custom error pages!!

Posted by Pankaj Bhagat <pb...@reef.com>.
yup that sure is the problem i was also getting.

thanks for helping me outta that.......

n cheers.........
v have found a bug..........hahahaha

so guess a lot of ppl. like us wont have to waste their time on it....

regards
Pankaj
----- Original Message -----
From: "Kief Morris" <ki...@bitBull.com>
To: <to...@jakarta.apache.org>
Sent: Tuesday, December 12, 2000 3:41 PM
Subject: Re: Custom error pages!!


> Pankaj Bhagat typed the following on 14:58 12/12/2000 +0100
> >The only difference in what i was trying previously and this one is that
> >........for an error page i was going to an html file whereas now its
> >working if i redirect to a jsp.
>
> Aha, someone else just pointed this out.
>
> >Dont know why.........but till the time it works i guess its fine.
> >
> >I also dont know if thats a bug with Tomcat 3.2 or not.
>
> I think there is a bug, the spec says:
>
> "The location element contains the location of the resource in the
> web application relative to the root of the web application. The
> value of the location must have a leading '/'."
>
> The spec seems to include static (html, gif) files in its definition of
"resources",
> so it ought to work.
>
> I tried it with an html file and Tomcat chokes: I get:
>
> java.lang.StackOverflowError
> at java.io.FileNotFoundException.(FileNotFoundException.java:62)
> at java.io.FileInputStream.open(Native Method)
> at java.io.FileInputStream.(FileInputStream.java:64)
> at java.io.FileInputStream.(FileInputStream.java:95)
> at
org.apache.tomcat.request.FileHandler.doService(StaticInterceptor.java:365)
> at org.apache.tomcat.core.Handler.service(Handler.java:286) at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372) at
org.apache.tomcat.core.ContextManager.handleStatus(ContextManager.java:1049)
at
org.apache.tomcat.request.FileHandler.doService(StaticInterceptor.java:387)
at org.apache.tomcat.core.Handler.service(Handler.java:286) at
> org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
>
> ... seems to be a recursive loop.
>
> My web.xml file contains:
>
> <error-page>
> <error-code>404</error-code>
> <location>/foo.html</location>
> </error-page>
>
> <error-page>
> <exception-type>java.lang.NullPointerException</exception-type>
> <location>/foo.html</location>
> </error-page>
>
> And /foo.html definitely exists, I can view it normally if I point my
browser
> straight at it.
>
> I'll report the bug.
>
>
> ---
>               bitBull makes the Internet bite:
http://www.bitBull.com/demos/
>


Re: Custom error pages!!

Posted by Kief Morris <ki...@bitBull.com>.
Pankaj Bhagat typed the following on 14:58 12/12/2000 +0100
>The only difference in what i was trying previously and this one is that
>........for an error page i was going to an html file whereas now its
>working if i redirect to a jsp.

Aha, someone else just pointed this out.

>Dont know why.........but till the time it works i guess its fine.
>
>I also dont know if thats a bug with Tomcat 3.2 or not.

I think there is a bug, the spec says:

"The location element contains the location of the resource in the
web application relative to the root of the web application. The
value of the location must have a leading �/�."

The spec seems to include static (html, gif) files in its definition of "resources",
so it ought to work.

I tried it with an html file and Tomcat chokes: I get:

java.lang.StackOverflowError 
at java.io.FileNotFoundException.(FileNotFoundException.java:62) 
at java.io.FileInputStream.open(Native Method) 
at java.io.FileInputStream.(FileInputStream.java:64) 
at java.io.FileInputStream.(FileInputStream.java:95) 
at org.apache.tomcat.request.FileHandler.doService(StaticInterceptor.java:365) 
at org.apache.tomcat.core.Handler.service(Handler.java:286) at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372) at org.apache.tomcat.core.ContextManager.handleStatus(ContextManager.java:1049) at org.apache.tomcat.request.FileHandler.doService(StaticInterceptor.java:387) at org.apache.tomcat.core.Handler.service(Handler.java:286) at 
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372) 

... seems to be a recursive loop.

My web.xml file contains:

	<error-page>
		<error-code>404</error-code>
		<location>/foo.html</location>
	</error-page>
	
	<error-page>
		<exception-type>java.lang.NullPointerException</exception-type>
		<location>/foo.html</location>
	</error-page>

And /foo.html definitely exists, I can view it normally if I point my browser
straight at it.

I'll report the bug.


---
              bitBull makes the Internet bite: http://www.bitBull.com/demos/


Re: Custom error pages!!

Posted by Pankaj Bhagat <pb...@reef.com>.
Thanks a lot for ur help atleast now i am atleast near to the solution.

Hey but i was just aping what you suggested and it worked.

The only difference in what i was trying previously and this one is that
........for an error page i was going to an html file whereas now its
working if i redirect to a jsp.

Dont know why.........but till the time it works i guess its fine.

I also dont know if thats a bug with Tomcat 3.2 or not.

Thanks and Regards
Pankaj
----- Original Message -----
From: "Kief Morris" <ki...@bitBull.com>
To: <to...@jakarta.apache.org>
Sent: Tuesday, December 12, 2000 1:32 PM
Subject: Re: Custom error pages!!


> Pankaj Bhagat typed the following on 12:58 12/12/2000 +0100
> >But just for information, can you comment on the <error-pages> tag not
> >working in the deployment descriptor of Tomcat 3.2
>
> I just tried it, it works fine for me. Are you specifying the full names
of the
> exceptions? e.g. java.lang.IllegalArgumentException rather than just
> IllegalArgumentException.
>
> Here's what worked for me in my WEB-INF/web.xml file, Tomcat 3.2 final.
>
> <error-page>
> <error-code>404</error-code>
> <location>/not_found.jsp</location>
> </error-page>
>
> <error-page>
> <exception-type>java.lang.NullPointerException</exception-type>
> <location>/error.jsp</location>
> </error-page>
>
> Kief
>
> ---
>               bitBull makes the Internet bite:
http://www.bitBull.com/demos/
>


Re: Custom error pages!!

Posted by Kief Morris <ki...@bitBull.com>.
Pankaj Bhagat typed the following on 12:58 12/12/2000 +0100
>But just for information, can you comment on the <error-pages> tag not
>working in the deployment descriptor of Tomcat 3.2

I just tried it, it works fine for me. Are you specifying the full names of the
exceptions? e.g. java.lang.IllegalArgumentException rather than just
IllegalArgumentException.

Here's what worked for me in my WEB-INF/web.xml file, Tomcat 3.2 final.

	<error-page>
		<error-code>404</error-code>
		<location>/not_found.jsp</location>
	</error-page>
	
	<error-page>
		<exception-type>java.lang.NullPointerException</exception-type>
		<location>/error.jsp</location>
	</error-page>
	
Kief

---
              bitBull makes the Internet bite: http://www.bitBull.com/demos/


Re: Custom error pages!!

Posted by Pankaj Bhagat <pb...@reef.com>.
Thanks for your response. The solution really sounds good.

But just for information, can you comment on the <error-pages> tag not
working in the deployment descriptor of Tomcat 3.2

Anybody else who has been successful with this can also plese comment.

Regards
Pankaj
----- Original Message -----
From: "Kief Morris" <ki...@bitBull.com>
To: <to...@jakarta.apache.org>
Sent: Tuesday, December 12, 2000 12:26 PM
Subject: Re: Custom error pages!!


> Pankaj Bhagat typed the following on 11:58 12/12/2000 +0100
> >So now what i can understand is that it should be Tomcat's problem to
> >intercept any errors occuring in the servlet and then passing me onto the
> >specified url in the deployment descriptor.
>
> I believe this only applies to JSP pages. For your servlet, you should
just
> catch it normally:
>
> public void doGet (...)
> {
>     try {
>         // your code here
>     } catch (Throwable e) {
>         // forward to an error page
>     }
>     // write headers and output
> }
>
> If you want to take advantage of JSP error page handling, a slick thing to
do
> might be to insert the Throwable object into the request as an attribute
> named "javax.servlet.jsp.jspException", then forward to a JSP page whose
> page directive includes the parameter isErrorPage="true". This will
automatically
> create a variable called "exception" in the error page, which will be a
reference
> to the Throwable object you set in the request.
>
> Check out section 2.7.1 of the JSP specification document for details on
how
> this works.
>
> Kief
>
> ---
>               bitBull makes the Internet bite:
http://www.bitBull.com/demos/
>


Re: Custom error pages!!

Posted by Kief Morris <ki...@bitBull.com>.
Pankaj Bhagat typed the following on 11:58 12/12/2000 +0100
>So now what i can understand is that it should be Tomcat's problem to
>intercept any errors occuring in the servlet and then passing me onto the
>specified url in the deployment descriptor.

I believe this only applies to JSP pages. For your servlet, you should just
catch it normally:

public void doGet (...)
{
    try {
        // your code here
    } catch (Throwable e) {
        // forward to an error page
    }
    // write headers and output
}

If you want to take advantage of JSP error page handling, a slick thing to do 
might be to insert the Throwable object into the request as an attribute 
named "javax.servlet.jsp.jspException", then forward to a JSP page whose 
page directive includes the parameter isErrorPage="true". This will automatically
create a variable called "exception" in the error page, which will be a reference
to the Throwable object you set in the request.

Check out section 2.7.1 of the JSP specification document for details on how
this works.

Kief

---
              bitBull makes the Internet bite: http://www.bitBull.com/demos/


Re: Custom error pages!!

Posted by Pankaj Bhagat <pb...@reef.com>.
Thanks Kief for your fast response.
I'll try and explain in a better way what i am tryin to achieve.

I am presently working on a product and here all the calls to jsp/html/etc.
are routed through a single servlet. And we are using Apache 1.3 as the web
server and Tomcat 3.2 as the servlet/jsp runner.
Now what i wish to do is to catch an exception which may occur anywhere but
is passed on to this servlet and then redirect me to a specific error page.
So i can have general exceptions like "ObjectNotFoundException" which may
occur in any page but being passed on to the servlet.

Now for this i was exploring the option in Tomcat3.2 (rather in the servlet
2.2 spec.'s) which say that at the time of deployment of a servlet we can
also specify certain specific error pages in the web.xml file with the tags
"error-pages".

So now what i can understand is that it should be Tomcat's problem to
intercept any errors occuring in the servlet and then passing me onto the
specified url in the deployment descriptor.

Now just to take no chances i also did some configuration in Apache also
(using the directive "ErrorDocument")........but think this can be ignored
right now.

Hope the problem is a bit more clear. And hope you can suggest me some
alternative.

Regards
Pankaj



----- Original Message -----
From: "Kief Morris" <ki...@bitBull.com>
To: <to...@jakarta.apache.org>
Sent: Tuesday, December 12, 2000 11:35 AM
Subject: Re: Custom error pages!!


> Pankaj Bhagat typed the following on 11:17 12/12/2000 +0100
> >I want Custom error pages, in my application, the two solutions i have is
to use the "ErrorDocument" directive in Apache or to use the "error-pages"
xml element while deploying my servlet in Tomcat (please note that i am
using Apache 1.3 and Tomcat 3.2). But somehow both of them are not
responding to the changes i try to make. Am only getting some satisfaction
if i try and call a page which does not exist through Apache (with
netscape.......IE.......still does nothing).
>
> I don't completely understand what you're trying to do. What kinds of
errors are you
> trying to catch with customized pages, and what are you doing to test it?
>
> JSP errors pages will only be displayed by Tomcat when there is a Java
exception
> processing a JSP page which has the error page configured like:
>
>     <%@ page language="java" errorPage="/error.jsp"%>
>
> It won't work if the exception is thrown after the headers have already
been sent
> to the client, as when you use autoFlush=true.
>
> The Apache httpd error pages aren't really on topic here, since they don't
involve
> Tomcat.
>
> Kief
>
>
> ---
>               bitBull makes the Internet bite:
http://www.bitBull.com/demos/
>


Re: Custom error pages!!

Posted by Kief Morris <ki...@bitBull.com>.
Pankaj Bhagat typed the following on 11:17 12/12/2000 +0100
>I want Custom error pages, in my application, the two solutions i have is to use the "ErrorDocument" directive in Apache or to use the "error-pages" xml element while deploying my servlet in Tomcat (please note that i am using Apache 1.3 and Tomcat 3.2). But somehow both of them are not responding to the changes i try to make. Am only getting some satisfaction if i try and call a page which does not exist through Apache (with netscape.......IE.......still does nothing).

I don't completely understand what you're trying to do. What kinds of errors are you
trying to catch with customized pages, and what are you doing to test it? 

JSP errors pages will only be displayed by Tomcat when there is a Java exception
processing a JSP page which has the error page configured like:

    <%@ page language="java" errorPage="/error.jsp"%>

It won't work if the exception is thrown after the headers have already been sent
to the client, as when you use autoFlush=true.

The Apache httpd error pages aren't really on topic here, since they don't involve
Tomcat.

Kief


---
              bitBull makes the Internet bite: http://www.bitBull.com/demos/