Annotation in Servlet

  • On September 26, 2005, Sun Microsystems and the Java Specification Request 315 Expert Group issued a maintenance release of the Servlet API.

  • The Release Servlet 3.0 added several new features and changes.

  • In Servlet 3.0, several new annotations are defined for ease of development,these annotations are placed in the package javax.servlet.annotation.

  • New set of annotations introduced that can be used by developers rather than put the data in the configuration file(XML)or intended to provide meta data only.

  • In other words,need to extend the corresponding class or implement the corresponding interface.

    1. The following annotations are applicable starting from Servlet 3.0 specification:-

    2. @WebServlet:- annotation is used to declare a servlet.

    3. @ServletFilter:- to declare a filter.

    4. @WebServletContextListener:- to define ServletContextListeners.

    public class MyServlet  extends HttpServlet {
        public void doGet(...) {
  • This Java Specification Request (JSR) has been approved in the form of JSR 315 and is planned to be part of Java Enterprise Edition 6 or higher.
  • Requirements:
    There are following requirements:-

  • first is, JDK6 or higher version must be installed and its path in the environment variable be set in your computer.

  • Second ,You must have the Tomcat7 application server.

  • Third, you should have Eclipse helios (or higher version )because the lower version may not support the tomcat7.