繁体   English   中英

将Struts2动作限制为仅发布方法

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM