【发布时间】:2014-11-24 16:27:43
【问题描述】:
这是我的代码:
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.StrutsStatics;
@SuppressWarnings("serial")
public class PostOnlyInterceptor extends AbstractInterceptor {
@Override
public String intercept(ActionInvocation ai) throws Exception {
final ActionContext context = ai.getInvocationContext();
HttpServletRequest request = (HttpServletRequest) context.get(StrutsStatics.HTTP_REQUEST);
if (!request.getMethod().equals("POST")) {
return Action.ERROR;
}
return ai.invoke();
}
}
出于安全原因,我使用此拦截器来避免“GET”方法请求。但是当我使用链操作方法调用它时:request.getMethod() 返回 GET 请求。
那么如何处理这种情况呢?
【问题讨论】:
标签: java struts2 get interceptor chaining