Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Many error code for the same location?  RSS feed

 
Renato Losio
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wandering if it's possible to trap different error-code within the same error-page. Basically I don't like to repeat the error-page fragment in the web.xml with the same location.

Checking the specs, looks like I can't simply nest them:

<!ELEMENT error-page ((error-code | exception-type), location)>

Any other option?

Cheers,

Renato
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you can do using multiple tags having same location but different error code.
 
Renato Losio
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I will do that way. But I'm still a bit lazy and:

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

sounds too long to me :-)

I would be much better type something like:

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

Cheers,

Renato
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to write

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

for each HTTP error code.

Other way is using

HttpServletResponse.sendError(error_code,string_message);

Which will display server's default error page with error code and string message to the user.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Renato Losio:
I would be much better type something like:

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



I do not think we can do it in this way.Check the DTD for web.xml.According to that its not possible.(I mean multiple error code in one errorpage tag.)
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An alternative to the error-code element, is the exception-type element.


From the servlet spec (link in my signature):

15. error-page Element
The error-page contains a mapping between an error code or an exception
type to the path of a resource in the Web application. The sub-element
exception-type contains a fully qualified class name of a Java exception type.
The sub-element 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 �/�.




 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!