1. 程式人生 > >JavaEE架構簡介與JavaWeb新特性

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