jquery - Ajax jquery 和 struts2 拦截器的参数

标签 jquery ajax struts2 interceptor

我使用 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/

相关文章:

php - 如何连续运行 PHP 脚本?

ajax - AJAX 是否可以在 AMP 中加载嵌入?

java - 如何在 Struts 2 中将 QRCode 图像从操作类发送并显示到 JSP

java - 支柱2 : Action classes

javascript - 试图在 jquery 中将此菜单与此数据连接

javascript - jquery在点击另一个对象时开始拖动对象

javascript - 有条件地加载 javascript 文件中的 js 部分 WordPress

java - AJAX 请求发送 null 参数到 Java Spring Controller

java - addFieldError 中出现错误 <s :select> in Struts2

javascript - 使用 jQuery 遍历列表