美文网首页
springboot装载servlet

springboot装载servlet

作者: 要不再等等 | 来源:发表于2019-09-21 23:44 被阅读0次

    方法一:
    @WebServlet(urlPatterns = "/test2")
    public class TestServlet extends HttpServlet
    {
    //重写get方法
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    //设置返回类型为json
    response.setContentType("application/json");
    //设置返回字符集
    response.setCharacterEncoding("utf-8");
    //输出对象
    PrintWriter writer = response.getWriter();
    //输出error消息
    writer.write("执行TestServlet内doGet方法成功!");
    writer.close();
    }
    }
    @Configuration
    @ServletComponentScan
    public class ServletConfiguration {

    /*@Bean
    public ServletRegistrationBean servletRegistrationBean()
    {
        return new ServletRegistrationBean(new TestServlet(),"/test");
    }*/
    

    }

    相关文章

      网友评论

          本文标题:springboot装载servlet

          本文链接:https://www.haomeiwen.com/subject/hmbuyctx.html