1、先配置struts.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="default" namespace="/" extends="struts-default">
<interceptors>
<interceptor name="demoInterceptor" class="com.struts2zj.interceptor.DemoInterceptor">
</interceptor>
<interceptor-stack name="selfStack">
<interceptor-ref name="demoInterceptor"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
</interceptor-stack>
</interceptors>
</package>
</struts>
2、java文件添加注解
@ParentPackage("default")
public class UserAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = -1818573197017773207L;
@Action(value="userAction",interceptorRefs= {@InterceptorRef(value = "selfStack")})
@Override
public String execute() throws Exception {
System.out.println("8888888888");
return NONE;
}
}
其中@ParentPackage一定要配置,不配置会报错。