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
原文地址:https://www.cnblogs.com/tanlei-sxs/p/10055992.html
时间: 2024-11-11 05:48:48