Error Handling Jsp Servlet
Contents |
QuestionsJava Interview QuestionsJDBC Interview QuestionsServlet Interview QuestionsJSP Interview QuestionsStruts2 Interview QuestionsSpring Interview QuestionsHibernate Interview QuestionsJSF Interview session handling in servlet and jsp QuestionsResourcesStoreHome » Java » Java EE » Servlet error handling in jsp with example Exception and Error Handling Example TutorialServlet Exception and Error Handling Example TutorialJuly jsp error handling and debugging 14, 2016 by Pankaj 13 Comments Today we will look into Servlet Exception and Error Handling. Sometime back I
Error Handling Php
wrote a post about Exception Handling in Java but when it comes to web application, we need more than normal exception handling in java.Servlet ExceptionIf you notice, doGet() and doPost() methods throw javax.servlet.ServletException and IOException, let's see what error handling javascript happens when we throw these exception from our application. I will write a simple servlet that will throw the ServletException. package com.journaldev.servlet.exception; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet("/MyExceptionServlet") public class MyExceptionServlet extends HttpServlet { private static final long serialVersionUID = 1L; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { throw new ServletException("GET method is not supported."); } } Now when we invoke this servlet through browser with GET method, we get response like below image.Since browser understand only HTML, when our application throw exception, servlet container processes the exception and generate a HTML response. This logic is specific to servlet container. I am using tom
Servlets - Life Cycle Servlets - Examples Servlets - Form Data Servlets - Client Request Servlets - Server error handling java Response Servlets - Http Codes Servlets - Writing Filters Servlets
J2ee Error Handling
- Exceptions Servlets - Cookies Handling Servlets - Session Tracking Servlets - Database Access Servlets
Servlet Exception Handling Examples
- File Uploading Servlets - Handling Date Servlets - Page Redirect Servlets - Hits Counter Servlets - Auto Refresh Servlets - Sending Email Servlets - http://www.journaldev.com/1973/servlet-exception-and-error-handling-example-tutorial 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 http://www.tutorialspoint.com/servlets/servlets-exception-handling.htm 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.
▼ JSP Tutorial JSP Introduction Life cycle of JSP JSP API JSP in Eclipse JSP scripting elements JSP scriptlet tag JSP expression tag JSP http://www.javatpoint.com/exception-handling-in-jsp declaration tag 9 Implicit Objects JSP Request JSP Response JSP Config JSP Application JSP Session JSP PageContext JSP Page JSP Exception JSP Directive Elements JSP page directive JSP include directive JSP taglib directive JSP Exception Action Elements jsp:forward jsp:include Java Bean class jsp:useBean set & getProperty Displaying applet in JSP Expression Language MVC in JSP JSTL JSP Custom tags error handling Example of Custom Tag Attributes Iteration Custom URI JSP Pagination JSP Pagination Example JSP CRUD JSP CRUD Example Development in JSP Registration Form Login Form Uploading File Downloading File Interview Questions JSP Quiz next>> <