[英]Restrict Struts2 Action to Post Method Only
我們如何限制Struts2動作僅適用於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批注將您的操作與該程序包相關聯。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.