@WebServlet注解的使用


import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.annotation.WebServlet;

@WebServlet(name="Index",urlPatterns={"/index.do"})
public class Index extends HttpServlet
{

        @Override
        public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException
        {

        }
        @Override
        public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException
        {
                doGet(request,response);
        }
}

其中name即servlet-name,urlPatterns即url-pattern
注意使用webservlet要将web.xml从WEB-INF中删除否则webservlet不会生效

你可能感兴趣的:(@WebServlet注解的使用)