2014-07-23 81 views
2

我有一个Ajax调用与jquery方法是工作很好,但现在我已经添加了一个拦截器的行动阿贾克斯被调用,我不能接收这些参数ñ行动 我认为拦截器挡着,我所有的Ajax参数,使..什么我可以做的,是我的代码参数与Ajax的jQuery和struts2拦截

的Ajax功能

 $.ajax({ 
     url: "editLab", 
     type: "POST", 
     dataType: "json", 
     data: { 
      name: $('#lab').val(), 
      option: $('#option').val() 
     }, 
     success: function(response) { 
      alert(response.name); 
     } 
    }); 

行动(前) 我alert()打印的名称与data:参数传递

@ParentPackage(value = "inter") 
@Action(value = "editLab", results = { 
    @Result(type = "json", name = "success")}) 
public class MyAction extends ActionSupport { 

行动(现在) 我alert()打印空看来我的拦截阻止我与.ajax

@ParentPackage(value = "inter") 
@InterceptorRefs({ 
    @InterceptorRef("interceptor") 
}) 
@Action(value = "editLab", results = { 
    @Result(type = "json", name = "success")}) 
public class MyAction extends ActionSupport { 

发送参数是有一种方式来获得与拦截器的参数,然后发送到我的行动再次?

拦截BTW

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; 
    } 

} 

回答

1
@ParentPackage(value = "inter") 
@InterceptorRefs({ 
    @InterceptorRef("interceptor"), @InterceptorRef("defaultStack") 
}) 
@Action(value = "editLab", results = { 
    @Result(type = "json", name = "success")}) 
public class MyAction extends ActionSupport { 

我想你会需要添加含有参数界面基本上转储在值栈的所有请求参数defaultStack拦截参考。

+0

是的,这是我不得不修改我的软件包,但现在它的工作原理。谢谢 –