• Post Reply Bookmark Topic Watch Topic
  • New Topic

customize error message

 
Tsehau Chao
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm quite new at JSP but already know how to create error pages to catch exceptions and HTTP error codes and stuff. What I'm wondering now is how do I customize the actual error message *after* I have the error page?

To keep files to a minimum, I would like to have just one general purpose error.jsp, but I'm not sure how to determine the actual exception or error code(404/500...) once I'm on the error page.

Any pointers appreciated, thanks!
 
Shahnawaz Shakil
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the Web container receives or generates an exception or system error, it initializes several variables as request attributes. Following are those variables.
javax.servlet.error.status_code,
javax.servlet.error.exception_type,
javax.servlet.error.message,
javax.servlet.error.exception,
javax.servlet.error.request_uri
Thus you can get the status code as follows:
Object status_code = req.getAttribute("javax.servlet.error.status_code");
You can make use of this status code in an if else statement to customize your message.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tsehau Chao:


I would like to have just one general purpose error.jsp, but I'm not sure how to determine the actual exception or error code(404/500...) once I'm on the error page.



Then,what is the problem in using <error-page> tag in web.xml ?
 
Tsehau Chao
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Shahnawaz, that's what I was looking for. However when I try to do the following, things don't go quite as expected:



Error lands on tomcat's default error page instead.

I'm quite positive that the problem lies in the test condition syntax (JSTL is correctly installed), but with my limited knowledge I don't know how to fix it Thanks in advance.
 
Tsehau Chao
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind, turns out it was a minor syntax error, changing to single quotes solved the problem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!