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);
    }
}
posted @ 2021-09-14 19:49  不是孩子了  阅读(36)  评论(0)    收藏  举报