【发布时间】:2012-11-12 01:40:24
【问题描述】:
我们如何限制 Struts2 Action 只对 Post 方法起作用?
【问题讨论】:
我们如何限制 Struts2 Action 只对 Post 方法起作用?
【问题讨论】:
为什么要这样做?
除了这里是你如何做到这一点......
//Following has not been tested
package com.quaternion.interceptor;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
public class PostOnlyInterceptor extends AbstractInterceptor {
@Override
public String intercept(ActionInvocation ai) throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
if (!request.getMethod().equals("POST")){
return Action.ERROR;
}
return ai.invoke();
}
}
然后为特定包构建拦截器堆栈,并将您的操作放入该包中或使用注释将您的操作与使用 ParentPackage 注释的包关联。
【讨论】: