zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    .net事件和委托
    DataFormatString使用笔记
    DropDownList 绑定 枚举 Enum
    iOS开发如何实现消息推送机制
    JQuery调用asp.net后台方法
    Android 服务器推送技术
    Jquery Ajax ashx DataTable 传参 获取参数 C#
    jquery 基础
    [Perl书籍合集]Perl eBooks Collection
    LISP之根源
  • 原文地址:https://www.cnblogs.com/atomgame/p/12510131.html
Copyright © 2011-2022 走看看