Javax.servlet.error.request_uri
and Type Constant Field Value publicstaticfinaljava.lang.String ASYNC_CONTEXT_PATH "javax.servlet.async.context_path" publicstaticfinaljava.lang.String ASYNC_PATH_INFO "javax.servlet.async.path_info" publicstaticfinaljava.lang.String ASYNC_QUERY_STRING "javax.servlet.async.query_string" publicstaticfinaljava.lang.String ASYNC_REQUEST_URI "javax.servlet.async.request_uri" publicstaticfinaljava.lang.String ASYNC_SERVLET_PATH "javax.servlet.async.servlet_path" javax.servlet.RequestDispatcher Modifier and Type Constant Field Value publicstaticfinaljava.lang.String ERROR_EXCEPTION "javax.servlet.error.exception" publicstaticfinaljava.lang.String ERROR_EXCEPTION_TYPE "javax.servlet.error.exception_type" publicstaticfinaljava.lang.String ERROR_MESSAGE "javax.servlet.error.message" publicstaticfinaljava.lang.String ERROR_REQUEST_URI "javax.servlet.error.request_uri" publicstaticfinaljava.lang.String ERROR_SERVLET_NAME "javax.servlet.error.servlet_name" publicstaticfinaljava.lang.String ERROR_STATUS_CODE "javax.servlet.error.status_code" publicstaticfinaljava.lang.String FORWARD_CONTEXT_PATH "javax.servlet.forward.
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How to get the message in a custom error page (Tomcat)? up vote 23 down vote favorite 7 In JSPs, you may use response.sendError(int code, String message) to return a particular error code (eg 404 for not found) and a message https://tomcat.apache.org/tomcat-7.0-doc/servletapi/constant-values.html as well. These messages display fine, as long as you use the default ugly Tomcat error pages. However, if you create a custom error page, how do you get that message? I've tried exception.getMessage() or pageContext.getErrorData() but no avail. I've been searching for this for like hours and nobody seems to even wonder about the same thing! :S I forgot to mention I've only tried it with 404s so far, since that's what I need most... The exception is null for some reason, so http://stackoverflow.com/questions/995248/how-to-get-the-message-in-a-custom-error-page-tomcat trying anything on it throws a NullPointerException. The error page is a 404 error page, set via web.xml (since I want it to be displayed for EVERY single 404 error) and for anyone wondering, yes it has the isErrorPage directive set to true... jsp tomcat custom-error-pages share|improve this question edited Jun 15 '09 at 14:51 asked Jun 15 '09 at 9:46 Lea Verou 13.8k63142 Does your custom 404 page never work? How do you check if it works? Have you check if the below by me mentioned request attributes exist? Last resort try this tutorial playground.greyscale.se/wiki/en/Custom_404_page_in_Tomcat –jitter Jun 15 '09 at 15:48 No it works fine. I just don't know how to get the message, if set via response.sendError(). –Lea Verou Jun 15 '09 at 16:27 response.sendError() will send error to your clients browser. It will not go to your error page after that unless you will do it yourself I think. –Georgy Bolyuba Jun 15 '09 at 22:10 Nope, it displays the custom error page just fine, as long as you properly set it via web.xml :) The only thing is that I don't know how to get the error message, if set. –Lea Verou Jun 16 '09 at 0:17 @LeaVerou, did you ever find a solution to this? –craig Feb 20 '12 at 21:13 | show 1 more comment 5 Answers 5 active oldest votes up vote 11 down vote The error message is available via javax.servlet.error.message a
When we develop a web application, we http://www.xyzws.com/jspfaq/how-to-get-the-real-requested-uri-from-inside-the-error-page/44 usually create a set of error pages, one for each error return code, or exception type. These error pages provides user friendly error message, https://coderanch.com/t/433436/java-Web-Component-OCEJWCD/certification/error-handling-servlet more inportantly, we can use these error pages to log what caused the error.The section of the web.xml may look like these:
Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums Forum: Web Component Certification (OCEJWCD) error handling servlet? Poonam Agarwal Ranch Hand Posts: 324 posted 7 years ago While handling business exceptions programatically using a RequestDispatcher, which of the following attributes would you set in the request? (Enthuware mock) 1. javax.servlet.error.status_code 2. javax.servlet.error.exception_type 3. javax.servlet.error.message 4. javax.servlet.error.exception 5. javax.servlet.error.servlet. The correct options are in bold. Can anybody please give me an example of forwrding a request to the error handing servlet by request.getRequestDispatcher()?? The explanation given by the Enthuware is:-- An error handler servlet should have access to 4 attributes: javax.servlet.error.status_code, javax.servlet.error.exception, javax.servlet.error.servlet_name, and javax.servlet.error.request_uri. So, if you are forwarding the request to an error handling servlet manualy using RequestDispatcher, you should set the above attributes in the request before forwarding the request to the servlet. javax.servlet.error.exception_type and javax.servlet.error.message are basically redundant because these can be derived from the javax.servlet.error.exception attribute which contains the exception object Thanks in advance Thanks
Poonam Agarwal SCWCD 86% Ankit Garg Sheriff Posts: 9536 33 I like... posted 7 years ago This is just simple. Suppose I have some file handling code in my servlet page. Now if there is some problem in the file handling, then I want to log the user out and then get him/her to the usual exception page, then I have two options, either I use this type of code try { //file handling } catch