springboot14-使用servlet--注解方式

时间:2021-09-16 19:35:29   收藏:0   阅读:40

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);
    }
}

原文:https://www.cnblogs.com/morehair/p/15269285.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!