[ 필터 ] 

:: 요청 - > 필터 -> 자원(JSP,서블릿 등) -> 필터 -> 응답

:: filter인터페이스를 구현 하고 있는 객체만 filter객체를 만들 수 있다.



[ 매서드 ]


 ☞ init매서드 

:: 객체 생성하고 생성자 실행하고 init매서드가 실행되는 것과 같음

:: 초기화 매서드

public void init(FilterConfig filterConfig) throws ServletException 



☞ doFilter매서드

:: 체인을 따라 다음에 존재하는 필터로 이동. 


public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws java.io.IOException, ServletException 



1. request파라미터를 이용하여 요청의 필터 작업 수행

2. 체인의 다음 필터 처리


chain.doFilter(request, response);



3. response를 이용해 응답의 필터링 작업 수행


☞ destroty매서드

:: 소멸 매서드


public void destroy() 




[ web.xml 추가 ]


<web-app ...>
    
    <filter>
        <filter-name>FilterName</filter-name>
        <filter-class>javacan.filter.FileClass</filter-class>
        <init-param>
           <param-name>paramName</param-name>
           <param-value>value</param-value>
        </init-param>
    </filter>
     
    <filter-mapping>
        <filter-name>FilterName</filter-name>
        <url-pattern>*.jsp</url-pattern>
    </filter-mapping>
    
    ...
</web-app>
 



[ web.xml ]


<filter>
    <filter-name>sitemesh</filter-name>
    <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
    </filter>
 
    <filter-mapping>
        <filter-name>sitemesh</filter-name>
        <url-pattern>/sitemesh/*</url-pattern>
    </filter-mapping>
 
cs


[ decorators.xml ]


<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/sitemesh/decorator">
    <decorator page="hello_decorator.jsp" name="main">
        <pattern>/sitemesh/hello.jsp</pattern>
        <pattern>/sitemesh/hello/*</pattern>
    </decorator>
    <decorator page="/sitemesh/decorator2/news_decorator.jsp" name="news">
        <pattern>/sitemesh/news/*</pattern>
    </decorator>
    <excludes>
        <pattern>/sitemesh/hello/exclude.jsp</pattern>
        <pattern>/sitemesh/news/exclude.jsp</pattern>
    </excludes>
</decorators>
cs


[ SiteMeshFilter ]


1. sitemesh-2.4.2.jar파일 추가

2. web.xml에 com.opensymphony.sitemesh.webapp.StigeMeshFilter 필터 추가

3. xml파일을 하나 더 생성하여 설정 추가(페이지 레이아웃 설정 및 URL패턴 정의)


:: 브라우저에서 요청이 들어오면 SiteMeshFilter가 요청을 대신 받고 전처리시 request를 처리하지 않고

  org.apache.jasper.servlet.JspServlet에게 위임한다. (JSPServlet은 web.xml에 정의되어 있다.)

:: menu.jsp파일에 대한 동적 파일 처리 완료 후 결과물로 html을 생성하여 SiteMeshfilter가 이를 받아 결과물을 추출후 레이아웃의 <prefix명:태그명 />

  부분에 삽입  

:: > /WEB-INF/decorators.xml 

:: 경로는 webcontent다음경로부터 지정해야한다.
















'프로그래밍 > JSP' 카테고리의 다른 글

MVC패턴  (0) 2018.07.31
Tiles  (0) 2018.07.31
파일 업로드  (0) 2018.07.27
JSTL  (0) 2018.07.25
EL  (0) 2018.07.24

+ Recent posts