首页 > 编程语言 > 详细

springboot14-使用servlet--注解方式

时间:2021-09-16 19:35:29      阅读:32      评论:0      收藏:0      [点我收藏+]

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--注解方式

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!