File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes BEA/Weblogic and the fly likes web.xml and error-page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » BEA/Weblogic
Bookmark "web.xml and error-page" Watch "web.xml and error-page" New topic
Author

web.xml and error-page

Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1850
Hi
I have added the following in my web.xml file
< error-page>
< error-code>404< /error-code>
< location>/error.html< /location>
< /error-page>

< error-page>
< error-code>500< /error-code>
< location>/error.html< /location>
< /error-page>

< error-page>
< exception-type>java.lang.RuntimeException< /exception-type>
< location>/error.html< /location>
< /error-page>
However the error-code do not work wihile the exception-type works. I have no idea why??. The same thing when implemented in the j2ee reference implementaion works fine.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

hi
Have u done response.setErrorCode(404)..


Groovy
Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1850
Why do i need that.

I have tried accessing a page index1.jsp that does not exist on my server and though the browser shows that a 404 response was received the error.html page was not seen.
This works fine in the j2ee reference implementation.
Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1850
Hi,
I added a jsp with the name response.jsp containing response.sendError(404) and the error.html page turns up fine.
The basic thing was that when I did not have a resource on my server lets say abc.jsp I wanted this file error.html to turn up. I thought the mapping in the web.xml file will help me as it does in j2ee reference implementation.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

To quote from sevlet spec
"...
The syntax allows the configuration of resources to be returned
by the container either when a servlet sets a status code to indicate an error on the
reponse, or if the servlet generates an exception or error that propogates to the
container.
If a status code indicating an error is set on the response, the container
consults the list of error page declarations for the web application that use the
status-code syntax and attempts a match. If there is a match, the container returns
the resource as indicated by the location entry.
[ September 09, 2002: Message edited by: Pradeep Bhat ]
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

In the servlet spec it is not mentioned whether the container will set the error code when it does not find the requested resource or we have to do it..
I always thought that the container will set the error code when it does not find the requested page. What do u feel Rahul?
Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1850
I always thought that the container will set the error code

I too felt the same. But now the problem is that Weblogic should have detected that the response is 404 and then forwarded the response to my error.html page.
But it does not seem to do so.
I have seen this work in some sample example in earlier versions of Weblogic, wherein a custom error page used to show up. Got to continue investigating
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Just check out this link
http://edocs.bea.com/wls/docs70/adminguide/web_server.html#resolve_http_req
In the table listed below the section "How WebLogic Server Resolves HTTP Requests" there is a case where 404 occurs and that column does contain a link which gives us a hint that when a resource is not found then the customized error page should be displayed.
Rahul, plz keep up informed with ur investigation.
Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1850
i checked this earlier
http://host ort/myFile.html

Where myfile.html does not exist in the apples Web Application and a default servlet has not been defined.
Does not matter
Error 404
For more information, see Customizing HTTP Error Responses.

But this does not help.
One question comes to my mind is that should I configure "default servlet" so that this will work??
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Hi Rahul,
But how will that help ?
Originally posted by Rahul Mahindrakar:
i checked this earlier
http://host ort/myFile.html

Where myfile.html does not exist in the apples Web Application and a default servlet has not been defined.
Does not matter
Error 404
For more information, see Customizing HTTP Error Responses.

But this does not help.
One question comes to my mind is that should I configure "default servlet" so that this will work??

Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1850
It states that if a file is not found then 404 response is returned.
My contention is that since a 404 response is being returned and since the web.xml contains a mapping between 404 and the \error.html file then the error.html file should be returned.
This does not seem to happen in Weblogic 7.0. But it works in j2ee referece implementation.
Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1850
so is this a bug in weblogic or are we not doing the right thing.
This problem does not take place in the case where exceptions are defined in web.xml file in weblogic.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Hi Rahul,
Just expereimented with JRUN 4.0
JRun 4.0 does display custom error page..

Originally posted by Rahul Mahindrakar:
so is this a bug in weblogic or are we not doing the right thing.
This problem does not take place in the case where exceptions are defined in web.xml file in weblogic.

[ September 09, 2002: Message edited by: Pradeep Bhat ]
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

try this
http://localhost:7001/webapp/someinvalidfile
I guess u must have missed webapp in the URL
Remember that this error code works only for the webapp containing the error code and not for the whole server.
So in ur case since ur searching for index1.jsp in some web app say wc then give this URL
http://localhost:7100/wc/index1.jsp
[ September 09, 2002: Message edited by: Pradeep Bhat ]
Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1850
I have missed the context root as my web application was the default application and hence did not require a context root.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Hi Rahul,
Dont forget to post ur progress here.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: web.xml and error-page