• JavaEE架构简介与JavaWeb新特性


    Fragment 

      将一个web应用做成几个部分,然后整合

          创建Fragment项目   然后打包放入Servlet项目中的WEB-INF下的lib中

    注解

    @WebServlet

    @WebServlet(
      initParams= {@WebInitParam(name="test1",value="123"),@WebInitParam(name="test2",value="456")}    ,
      loadOnStartup=0,
      urlPatterns={"/fragment","/test/fragment"}
    )

    getInitParameter("test1")
    getInitParameter("test2")//获得参数 根据名称

    @WebListner

    package com.tanlei.listner;
    
    import javax.servlet.ServletContextEvent;
    import javax.servlet.ServletContextListener;
    import javax.servlet.annotation.WebListener;
    
    @WebListener
    public class ServletListner implements ServletContextListener {
         @Override
        public void contextDestroyed(ServletContextEvent sce) {
            System.out.println("ContextListener contextDestroyed");
        }
         
         
         @Override
        public void contextInitialized(ServletContextEvent sce) {
             System.out.println("ContextListener contextInitialized");
        }
    }

    @WebFilter

    package com.tanlei.filter;
    
    import java.io.IOException;
    
    import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    import javax.servlet.annotation.WebFilter;
    
    @WebFilter("/*")
    public class TestFilter implements Filter {
       
        @Override
        public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)
                throws IOException, ServletException {
            System.out.println("TestFilter doFilter");
            System.out.println("FilterChain doFilter start");
            arg2.doFilter(arg0, arg1);
            System.out.println("FilterChain doFilter end");
        }
        
        @Override
        public void init(FilterConfig filterConfig) throws ServletException {
            System.out.println("TestFilter init");
        }
        
        @Override
        public void destroy() {
            System.out.println("TestFilter destroy");
        }
    
    }

    @Resource

  • 相关阅读:
    人人开源框架学习笔记
    Gitea安装笔记
    使用sdk方式获取微信的用户信息
    重写java类的equals()和hashCode方法
    Mysql 实现分页功能
    位运算应用和解析
    java代码POST方式请求SOAP
    java实现文件拷贝
    动态创建线程(多线程)处理大量数据
    ActiveMQ监听者接收信息
  • 原文地址:https://www.cnblogs.com/tanlei-sxs/p/10055992.html
Copyright © 2020-2023  润新知