码迷,mamicode.com
首页 > 其他好文 > 详细

servlet

时间:2019-04-24 12:03:52      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:ebs   pre   string   main   rgs   row   http   ons   protect   

1.实现httpservlet

@WebServlet("/some")
public class SomeServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.getWriter().print("some Servlet");
    }
}

2.

@SpringBootApplication
@ServletComponentScan("com.abc.servlet")  // 指定要扫描Servlet的包
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

 

----------------------------------------------------------------------------------------------------------------------------

          2.5

public class SomeServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.getWriter().print("some Servlet");
    }
}

 

在配置类中写

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    // 基于JavaConfig方式:适用于Servlet2.5+
    // 基于注解方式:适用于Servlet3.0+
    @Bean
    public ServletRegistrationBean<SomeServlet> getServlet() {
        return new ServletRegistrationBean<>(new SomeServlet(), "/some");
    }

}

 

servlet

标签:ebs   pre   string   main   rgs   row   http   ons   protect   

原文地址:https://www.cnblogs.com/mm163/p/10761497.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!