struts2 인터셉터(initerceptor) –
interceptor-stack
오라클자바커뮤니티에서 설립한 오엔제이프로그래밍
실무교육센터
(신입사원채용무료교육, 오라클SQL, 튜닝, 힌트,자바프레임워크, 안드로이드, 아이폰, 닷넷)
일반적인 웹 응용 프로그램에서 여러 개의 인터셉터들을 Action에 적용하게
되는데 각 Action마다 인터셉터 리스트를 반복해서 지정한다면 불편할 것이다. 이렇게 자주 사용되는 인터셉터 리스트를 모아서 지정한 것을
interceptor stack이라고 한다. 물론 interceptor-stack
내에 다른 interceptor-stack을 포함하는 것도 가능하다.
<interceptor-stack>안에 <interceptor-ref>를 사용해서
인터셉터를 지정한다.
<!-- Basic stack
-->
<interceptor-stack
name="basicStack">
<interceptor-ref
name="exception"/>
<interceptor-ref
name="servletConfig"/>
<interceptor-ref
name="prepare"/>
<interceptor-ref
name="checkbox"/>
<interceptor-ref
name="params"/>
<interceptor-ref
name="conversionError"/>
</interceptor-stack>
위에서
정의한 interceptor-stack의
name을 action Tag안에서 참조하면 된다.
<action ..>
<interceptor-ref
name=”basicStack”/>
……
</action>
[struts-default.xml의
defaultStack]
<interceptor-stack
name="defaultStack">
<interceptor-ref
name="exception"/>
<interceptor-ref
name="alias"/>
<interceptor-ref
name="servletConfig"/>
<interceptor-ref
name="prepare"/>
<interceptor-ref
name="i18n"/>
<interceptor-ref
name="chain"/>
<interceptor-ref
name="debugging"/>
<interceptor-ref
name="profiling"/>
<interceptor-ref
name="scopedModelDriven"/>
<interceptor-ref
name="modelDriven"/>
<interceptor-ref
name="fileUpload"/>
<interceptor-ref
name="checkbox"/>
<interceptor-ref
name="staticParams"/>
<interceptor-ref
name="params">
<param
name="excludeParams">dojo\..*</param>
</interceptor-ref>
<interceptor-ref
name="conversionError"/>
<interceptor-ref
name="validation">
<param
name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
<interceptor-ref
name="workflow">
<param
name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
</interceptor-stack>
일반적으로 default stack을 사용하면 충분하다. 그러나 사용하지 않는 인터셉터가 많다면 이 또한 성능에 영향을 줄 수 있으므로 최적화된 interceptor-stack을 만들어 사용하는 것이 좋다.
또한
미리 정의된 인터셉터 스택의 특정 인터셉터 파라미터를 바꿀 수 있는 방법이 있는데 “인터셉터이름.파라미터이름”을 name으로 갖는 파라미터를 정의하면 장위 패키지에서 정의한
파라미터를 오버라이드 할 수 있다.
<action name=…”>
<interceptor-ref
name=”defaultStack”>
<param
name="excludeMethods">myMethod</param>
</interceptor_ref>
댓글 없음:
댓글 쓰기