2012年4月10日 星期二

Sturt2 Iterceptor

Java Inteceptor
 @Override   
 public String intercept(ActionInvocation invocation) throws Exception { 
   java.util.Map<String,Object> session = invocation.getInvocationContext().getSession();
       if(session.isEmpty())
           return "session"; // session is empty/expired
       return invocation.invoke();
 }


sturs.xml 引用方式
<interceptors>            
<interceptor name="timeouthandle" class="com.taiwanmobile.ebg.util.SessionIterceptor" />           
<interceptor-stack name="sessionExpirayStack">
 <interceptor-ref name="timeouthandle" />
 <interceptor-ref name="defaultStack" />
 </interceptor-stack> 
</interceptors>           
<default-interceptor-ref name="sessionExpirayStack" />


<global-results>
 <result name="global-exception">/generalError.jsp</result>
 <result name="sql-exception">/SqlError.jsp</result>
 <result name="session">/timeoutError.jsp</result> 
</global-results>
<global-exception-mappings>
 <exception-mapping result="global-exception"
  exception="java.lang.Exception">
 </exception-mapping>
 <exception-mapping result="sql-exception"
  exception="java.sql.SQLException">
 </exception-mapping>
</global-exception-mappings>

<action name="helloInit" method="insertInit" class="test.testAction">
   <interceptor-ref name="sessionExpirayStack" /> 
   <result name="success">/qs/EBGQS100I1.jsp</result>
</action>

沒有留言:

張貼留言