Javax.servlet.error
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 Why there is an error in import javax.servlet.*? up vote 6 down vote favorite I am using JavaSE6 and Eclipse, there is an error in the line import javax.servlet.* It seems there is no jar for this import. How to fix it? Install anything, use Eclipse EE or add some dependency in Maven? java eclipse maven-2 maven share|improve this question edited Mar 6 '11 at 23:09 Tim Cooper 87k21162181 asked Mar 6 '11 at 23:08 user496949 22k82222350 Are you not using Eclipse IDE for JEE developers? –Buhake Sindi Mar 6 '11 at 23:11 add a comment| 5 Answers 5 active oldest votes up vote 8 down vote accepted The servlet API is not a part of the JDK, you need to add an additional dependency to your pom.xml. If this is for a webapp you can add this dependency with provided scope and the servlet container will make these classes available to your webapp at deployment time.
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 http://stackoverflow.com/questions/5214143/why-there-is-an-error-in-import-javax-servlet 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 https://www.tutorialspoint.com/servlets/servlets-exception-handling.htm 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. QuestionsJava Interview QuestionsJDBC Interview QuestionsServlet Interview QuestionsJSP Interview QuestionsStruts2 Interview QuestionsSpring Interview QuestionsHibernate Interview QuestionsJSF Interview QuestionsResourcesStoreHome » Java » Java EE » Servlet Exception and Error Handling Example TutorialServlet http://www.journaldev.com/1973/servlet-exception-and-error-handling-example-tutorial Exception and Error Handling Example TutorialJuly 14, 2016 by Pankaj http://www.xyzws.com/jspfaq/how-to-get-the-real-requested-uri-from-inside-the-error-page/44 13 Comments Today we will look into Servlet Exception and Error Handling. Sometime back I 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 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 tomcat and getting this error page. If you will use some other servers like JBoss or Glassfish, you might get different error HTML response.The problem with this response is that it's of no value to user. Also it's showing our application classes and server details to user that makes no sense to user and it's not good from security point of view.Servlet ErrorI am sure you must have seen 404 error when you are trying to hit a URL that doesn't exists. L When we develop a web application, we usually create a set of error pages, one for each error return code, or exception type. These error pages provides user friendly error message, more inportantly, we can use these error pages to log what caused the error.The section of the web.xml may look like these: