注册Servlet三大组件Servlet/Filter/Listener

注册Servlet

/**
* 自定义Servlet组件
*/
public class HelloServlet extends HttpServlet {
//快捷键 ctrl+o
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doPost(req,resp);
}

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.getWriter().write("helloServlet seccess...");
}
}




//注册Serlet组件
@Configuration
public class MyServletConfig {
@Bean
public ServletRegistrationBean helloServlet(){
      // 注册自己自定义组件
ServletRegistrationBean<HelloServlet> bean = new ServletRegistrationBean<>(new HelloServlet(), "/hello");
//设置servlet组件参数配置,如下面加载顺序
bean.setLoadOnStartup(1);
return bean;
}
}







注册Servlet三大组件Servlet/Filter/Listener

上一篇:008.Adding a model to an ASP.NET Core MVC app --【在 asp.net core mvc 中添加一个model (模型)】


下一篇:XPath的注入和预防