sprintboot 整合Servlet,Filter,Listener
Posted atomgame
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sprintboot 整合Servlet,Filter,Listener相关的知识,希望对你有一定的参考价值。
简介:
如果需要整合第三方框架时,可能还是不得不使用Servlet,Filter,Listener,Springboot中也有提供支持。
@WebServlet("/my") public class MyServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp){ doPost(req,resp); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp){ System.out.println("name>>>"+req.getParameter("name")); } }
@WebFilter("/*") public class MyFilter implements Filter { @Override public void init(FilterConfig filterConfig){ System.out.println("MyFilter>>>init"); } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { System.out.println("MyFilter>>>doFilter"); chain.doFilter(request,response); } @Override public void destroy() { System.out.println("MyFilter>>>destroy"); } }
@WebListener public class MyListener implements ServletRequestListener { @Override public void requestDestroyed(ServletRequestEvent sre) { System.out.println("MyListener>>>requestDestroyed"); } @Override public void requestInitialized(ServletRequestEvent sre) { System.out.println("MyListener>>>requestInitialized"); } }
三个组件使用@WebServlet,@WebFilter,@WebListener进行标记,启动类上添加@ServletComponentScan,实现对Servlet,Filter,以及Listener。
http://localhost:8080/my?name=tttt
以上是关于sprintboot 整合Servlet,Filter,Listener的主要内容,如果未能解决你的问题,请参考以下文章
javaEE中错误提示 Exception starting filter BackServletFilter java.lang.ClassNotFoundException: tmall.filt