1.Interceptor配置
<package name="sysManageServices" namespace="/" extends="struts-default">
<interceptors>
<interceptor name="reqCheck" class="interceptor.RequestInterceptor"/>
<interceptor-stack name="teamwareStack">
<interceptor-ref name="requestCheck"/>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="teamwareStack"/>
<action name="searchUserInfo" class="action.SearchUserInfoAction">
<result name="success">/page/userManage.jsp</result>
<result name="error">/page/result.jsp</result>
</action>
</package>
2.拦截器代码
package interceptor.RequestInterceptor;
import java.util.Map;
import javax.servlet.http.HttpSession;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
public class RequestInterceptor extends AbstractInterceptor {
private static final long serialVersionUID = 3244973830196015811L;
private HttpSession session;
public void setSession(Map<String, Object> session) {
this.session = (HttpSession) session;
}
public String intercept(ActionInvocation aInvocation) throws Exception {
// 获取请求的action名称
String actionName = aInvocation.getInvocationContext().getName();
// 获取action后附带参数
Map parameters = aInvocation.getInvocationContext().getParameters();
return Action.SUCCESS;
}
}