SERVLET3.0介绍

servlet3.0规范:

 

下面的说明适用从servlet 3.0规范的开始,

  • @WebServlet @ WebServlet
  • @WebServletContextListener @ WebServletContextListener
  • @ServletFilter @ ServletFilter
  • @InitParam @ InitParam

 以前基于xml的配置可以使用@WebServlet(name="UserAction", urlPatterns={"/UserAction"})这种注解的方式描述 SimpleServlet.java:

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package org.forever.bbs.web.action; import java.io.IOException; import java.io.PrintWriter; 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(name="UserAction", urlPatterns={"/UserAction"}) public class UserAction extends HttpServlet { protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { request.getRequestDispatcher("/WEB-INF/user/user_register.jsp") .forward(request, response); } finally { out.close(); } } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } @Override public String getServletInfo() { return "Short description"; }// </editor-fold> }

 

 

 

你可能感兴趣的:(Web,jsp,xml,servlet,bbs)