JavaEE架构简介与JavaWeb新特性
Posted 言西早石头侠
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
以上是关于JavaEE架构简介与JavaWeb新特性的主要内容,如果未能解决你的问题,请参考以下文章