New Features of Servlet3.0 (Tomcat7.0 and later) and new features of servlet3.0
@ WebServlet
Function
After a Servlet is created in Eclipse, Eclipse does not automatically generate the ing information of the Servlet in web. xml, but adds the annotation @ WebServlet to the Servlet code.
@ WebServlet is used to declare a class as Servlet. This annotation will be processed by the container during deployment, and the container will deploy the corresponding class as Servlet according to the specific attribute configuration.
Use
// Corresponds to the content in the servlet tag in the old version
@ WebServlet (displayName = "This is ForwordServlet", // description name = "ForwordServlet", // servlet name urlPatterns = {"/forwordServlet"}, // url loadOnStartup = 1, // startup Item initParams ={@ WebInitParam (name = "username", value = "James")} // initialize the parameter) public class ForwordServlet extends HttpServlet {private static final long serialVersionUID = 1L;/*** @ see HttpServlet # doGet (HttpServletRequest request, HttpServletResponse * response) */protected void doGet (HttpServletRequest request, httpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stub response. getWriter (). append ("Served :"). append (request. getContextPath ());}}