Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
Tags
- AWT
- 메소드
- 기본
- JSP
- Menu
- 예외처리
- JavaScript
- 국제화
- 안드로이드
- 배열
- Eclips
- 어노테이션
- layout
- 클래스
- 메서드
- 이클립스
- struts2
- HTML
- Android
- 에러페이지
- 생성자
- Graphic
- mybatis
- Spring
- 전화걸기
- paint
- oracle
- OGNL
- Java
- 오버로딩
Archives
- Today
- Total
note
struts2 커스텀 인터셉터 본문
struts-ch5.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="ch5" namespace="/ch5" extends="struts-default">
<interceptors>
<interceptor name="timer" class="com.ch5.interceptor.TimerInterceptor" />
</interceptors>
<!-- timer 인터셉터 활용 -->
<action name="helloWorld" class="com.ch4.action.HelloWorld">
<interceptor-ref name="timer" />
<interceptor-ref name="logger" />
<result name="success">/ch4/hello.jsp</result>
</action>
</package>
</struts>
struts.xml
<include file="struts-ch5.xml" />
TimerInterceptor.java
package com.ch5.interceptor;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
public class TimerInterceptor extends AbstractInterceptor{
private static Log log = LogFactory.getLog(TimerInterceptor.class);
@Override
public String intercept(ActionInvocation invocation) throws Exception {
//전처리
long startTime = System.currentTimeMillis();
//인터셉터 스택의 다음 인터셉터
//또는 마지막 인터셉터라면 액션 실행
String result = invocation.invoke();
//후처리
long executionTime = System.currentTimeMillis() - startTime;
log.info("실행 시간 :"+executionTime+"ms");
return result;
}
}
기존에 있던 파일을 실행했습니다
여러개의 interceptor가 연결이 되어 있을때
전처리 후처리에 의해
invoke 메세지를 매번 호출하는것이 아니라
연속적으로 연결이 되어 있으면
연동이 되어 마지막에 단 한번만 호출이된다
'JSP > Struts2' 카테고리의 다른 글
| struts2 chain (0) | 2012.02.22 |
|---|---|
| struts2 커스텀 인터페이스 (0) | 2012.02.22 |
| struts2 도메인 오브젝트 (0) | 2012.02.21 |
| Struts2 ActionSupport를 사용하여 유효성 검사(Interceptor) (1) | 2012.02.21 |
| Struts2 유효성 검사 (0) | 2012.02.21 |