springboot14-使用servlet--注解方式

1、编写servlet

@WebServlet(urlPatterns = "/myservlet")   //定义请求路径
public class MyServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.getWriter().println("MyServlet");
        resp.getWriter().flush();
        resp.getWriter().close();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}

2、配置扫描路径

@SpringBootApplication //开启spring配置
@ServletComponentScan(basePackages = "com.study.springboot.servlet")  //配置扫描路径
public class Springboot11ServletApplication {
    public static void main(String[] args) {
        SpringApplication.run(Springboot11ServletApplication.class, args);
    }
}

springboot14-使用servlet--注解方式

上一篇:C++程序运行提示0xc0000007b


下一篇:python requests 应用