Servlet3.0的注解自定义原生Servlet实战

Servlet3.0的注解自定义原生Servlet实战
  讲解:使用 Servlet3.0的注解自定义原生Servlet和Listener
    自定义原生Servlet

 package net.xdclass.demo.servlet;

 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(name = "userServlet",urlPatterns = "/v1/api/test/customs")
public class UserServlet extends HttpServlet{ @Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.getWriter().print("custom sevlet");
resp.getWriter().flush();
resp.getWriter().close();
} @Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
this.doGet(req, resp);
} }

浏览器输入:http://localhost:8083/v1/api/test/customs

结果:

Servlet3.0的注解自定义原生Servlet实战

注意:启动类中要加入@ServletComponentScan注解

上一篇:[翻译][Java]ExecutorService的正确关闭方法


下一篇:DroneCI启用privileged