gpt4 book ai didi

java - 将 Struts2 操作限制为仅发布方法

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:40:46 27 4
gpt4 key购买 nike

我们如何限制 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 注释将您的操作与包相关联。

关于java - 将 Struts2 操作限制为仅发布方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13337383/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com