我使用 jquery 方法进行了 Ajax 调用,效果很好,但现在我已经向 ajax 调用的操作添加了一个拦截器,并且我无法在操作中接收这些参数 我认为拦截器阻止了我所有的ajax参数所以..我在这里能做什么是我的代码
Ajax函数
$.ajax({
url: "editLab",
type: "POST",
dataType: "json",
data: {
name: $('#lab').val(),
option: $('#option').val()
},
success: function(response) {
alert(response.name);
}
});
Action (之前)
我的 alert()
打印通过 data:
参数传递的名称
@ParentPackage(value = "inter")
@Action(value = "editLab", results = {
@Result(type = "json", name = "success")})
public class MyAction extends ActionSupport {
行动(现在)
我的 alert()
打印 null 似乎我的拦截器正在阻止我使用 .ajax
@ParentPackage(value = "inter")
@InterceptorRefs({
@InterceptorRef("interceptor")
})
@Action(value = "editLab", results = {
@Result(type = "json", name = "success")})
public class MyAction extends ActionSupport {
有没有办法用拦截器获取参数,然后再次发送到我的操作?
拦截器顺便说一句
public class LoginAdminInterceptor implements Interceptor {
@Override
public void destroy() {
}
@Override
public void init() {
}
@Override
public String intercept(ActionInvocation actionInvocation) throws Exception {
String result = Action.LOGIN;
Map<String, Object> sesion = actionInvocation.getInvocationContext().getSession();
if (sesion.isEmpty()) {
return result;
}
if (!((User) (sesion.get("User"))).getProfile().isEmpty()) {
if (((User) (sesion.get("User"))).getProfile().equals("Admin")) {
System.out.println("Admin!");
result = actionInvocation.invoke();
}
}
return result;
}
}
最佳答案
@ParentPackage(value = "inter")
@InterceptorRefs({
@InterceptorRef("interceptor"), @InterceptorRef("defaultStack")
})
@Action(value = "editLab", results = {
@Result(type = "json", name = "success")})
public class MyAction extends ActionSupport {
我认为您需要添加 defaultStack
拦截器引用,其中包含参数接口(interface),该接口(interface)基本上将所有请求参数转储到值堆栈上。
关于jquery - Ajax jquery 和 struts2 拦截器的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24903177/