- package com.longzhun.interceptor;
- import com.opensymphony.xwork2.ActionInvocation;
- import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
- /**
- * @Title: MyInterceptor.java
- * @Package com.xxxxxxx.interceptor
- * @Description: TODO(添加描述)
- * @author longzhun
- * @date 2011-9-1 下午11:02:02
- * @version V1.0
- */
- public class MyInterceptor extends AbstractInterceptor {
- @Override
- public String intercept(ActionInvocation invocation) throws Exception {
- System.out.println("default interceptor start");
- String s = invocation.invoke();
- System.out.println("default interceptor end");
- return s;
- }
- }
- package com.longzhun.interceptor;
- import com.opensymphony.xwork2.ActionInvocation;
- import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
- /**
- * @Title: OtherInterceptor.java
- * @Package com.xxxxxxxx.interceptor
- * @Description: TODO(添加描述)
- * @author longzhun
- * @date 2011-9-1 下午11:20:58
- * @version V1.0
- */
- public class OtherInterceptor extends AbstractInterceptor {
- @Override
- public String intercept(ActionInvocation invocation) throws Exception {
- System.out.println("other interceptor start");
- String s = invocation.invoke();
- System.out.println("other interceptor end");
- return s;
- }
- }
struts.xml
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
- <struts>
- <constant name="struts.convention.package.locators" value="longzhun"/>
- <constant name="struts.convention.default.parent.package" value="curd-store"/>
- <constant name="struts.convention.result.path" value="/WEB-INF/jsp/"/>
- <package name="curd-store" extends="convention-default">
- <interceptors>
- <interceptor-stack name="defaultInterceporStack">
- <interceptor-ref name="defaultInterceptor"></interceptor-ref>
- </interceptor-stack>
- <interceptor name="defaultInterceptor" class="com.xxxxxxx.interceptor.MyInterceptor"/>
- <interceptor name="otherInterceptor" class="com.xxxxx.interceptor.OtherInterceptor"></interceptor>
- </interceptors>
- <default-interceptor-ref name="defaultInterceporStack"></default-interceptor-ref>
- </package>
- </struts>
HelloWorld.java
- package com.longzhun;
- import org.apache.struts2.convention.annotation.InterceptorRef;
- import org.apache.struts2.convention.annotation.InterceptorRefs;
- import org.apache.struts2.convention.annotation.Namespace;
- import com.opensymphony.xwork2.ActionSupport;
- /**
- * @Title: HelloWorld.java
- * @Package
- * @Description: TODO(添加描述)
- * @author longzhun
- * @date 2011-8-29 下午10:22:50
- * @version V1.0
- */
- @Namespace("/helloworld")
- @InterceptorRefs({
- @InterceptorRef("otherInterceptor"),
- @InterceptorRef("defaultInterceporStack")
- })
- public class HelloWorld extends ActionSupport{
- @Override
- public String execute() throws Exception {
- System.out.println("execute ok");
- return SUCCESS;
- }
- public String haha(){
- System.out.println("haha ok");
- return "haha";
- }
- }