Error Page Servlet 3.0
Servlets - Life Cycle Servlets - Examples Servlets - Form Data Servlets - Client Request Servlets - Server Response Servlets - Http Codes Servlets - Writing Filters Servlets - Exceptions Servlets - Cookies Handling Servlets - Session Tracking Servlets - Database Access Servlets - File Uploading Servlets - Handling Date Servlets - Page Redirect Servlets - Hits Counter Servlets - Auto Refresh Servlets - Sending Email Servlets - Packaging Servlets - Debugging Servlets - Internationalization Servlet Useful Resources Servlets - Questions and Answers Servlets - Quick Guide Servlets - Useful Resources Servlets - Discussion Selected Reading Developer's Best Practices Questions and Answers Effective Resume Writing HR Interview Questions Computer Glossary Who is Who Servlets - Exception Handling Advertisements Previous Page Next Page When a servlet throws an exception, the web container searches the configurations in web.xml that use the exception-type element for a match with the thrown exception type. You would have to use the error-page element in web.xml to specify the invocation of servlets in response to certain exceptions or HTTP status codes. web.xml Configuration: Consider, you have an ErrorHandler servlet which would be called whenever there is any defined exception or error. Following would be the entry created in web.xml. ErrorHandler ErrorHandler ErrorHandler /ErrorHandler 404 /ErrorHandler 403 /ErrorHandler javax.servlet.ServletException /ErrorHandler java.io.IOException /ErrorHandler If you want to
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 define and in servlet 3.0's web.xml-less? up vote 20 down vote favorite 3 I have existing web-app which I http://www.tutorialspoint.com/servlets/servlets-exception-handling.htm want to convert into web.xml-less of servlet's 3.0. I've managed to make it working, however there are 2 tags in web.xml which I still don't know the equivalent code in web.xml-less environment. /index.jsp 404 /pageNotFound Any help is appreciated java tomcat7 java-ee-6 servlet-3.0 share|improve this question asked Nov 19 '12 at 8:29 Wins 1,21221135 add a comment| 3 Answers 3 active oldest votes up vote 24 down vote accepted In http://stackoverflow.com/questions/13450044/how-to-define-welcome-file-list-and-error-page-in-servlet-3-0s-web-xml-less Servlets 3.0 you don't need a web.xml for many cases, however, sometimes it's required or just useful. Your case is just one of them - there is no special annotations to define welcome-file list or error-pages. Another thing is - would you really like to have them hardcoded? There are some valid use-cases for annotation / programmatic based configuration and for declarative configuration in XML. Moving to Servlets 3.0 doesn't necessarily means getting rid of web.xml at all cost. I would find the entries you posted a better example of configuration in XML. Firstly - they can be changed from deployment to deployment and secondly - they affect whole application and not any particular Servlet. share|improve this answer answered Nov 19 '12 at 8:37 Piotr Nowicki 10.6k53565 1 You're right, as long as the web.xml uses version 3.0, the container will load both web.xml and webservlet bootstrapper. –Wins Nov 30 '12 at 1:21 3 Exactly. Just mind the version you use and the metadata-complete attribute (either false or absent). It's always good to define the most current version you're using; I've prepared some empty XML files for most commonly used descriptors and published them here. You might find it useful. –Piotr Nowicki Nov 30 '12 at 8:18 1 Don't consider it as 'hard coded', but 'well coded'. JavaConfig ca
Board ExportXMLWordPrintable Details Type: Improvement Status: Open Priority: Major Resolution: Unresolved Affects Version/s: None Fix Version/s: None Labels: None Tags: FUTURE_RELEASE Description Web.xml can be programmatically created using Servlet 3.0. But features like https://java.net/jira/browse/SERVLET_SPEC-50 , < session-timeout> still needs to be configured in a web.xml.Can you provide a way to programmatically create these as well? Especially, error-page configuration. Activity Ascending order - Click to sort in descending order All Comments Work Log History Activity Hide Permalink Rajiv Mordani added a comment - 09/Jan/13 7:55 AM While we did provide programmatic APIs for error page adding servlets, filters and listeners, we have not exposed a full API for processing every element in the descriptor via APIs. Note that the programmatic APIs are not a complete replacement for the descriptor. It still makes sense to specify certain aspects via descriptors - just like in the case of annotations. Show Rajiv Mordani added a comment - 09/Jan/13 error page servlet 7:55 AM While we did provide programmatic APIs for adding servlets, filters and listeners, we have not exposed a full API for processing every element in the descriptor via APIs. Note that the programmatic APIs are not a complete replacement for the descriptor. It still makes sense to specify certain aspects via descriptors - just like in the case of annotations. Hide Permalink arjan tijms added a comment - 09/Feb/13 9:15 PM Ideally, every element (with some exceptions) would be settable in 3 ways, namely via: The traditional descriptor An annotation A high level programmatic API Note that JSF 2.2 introduced a method that's between the descriptor and the programmatic API: a call-back in which the descriptor is exposed as a DOM tree and can be programmatically manipulated. See http://jdevelopment.nl/jsf-22/#533 You could call this a low level programmatic API. It might make sense to adopt the JSF 2.2 method for web.xml. Show arjan tijms added a comment - 09/Feb/13 9:15 PM Ideally, every element (with some exceptions) would be settable in 3 ways, namely via: The traditiona