$ .ajax发布到struts2操作返回内部服务器错误 [英] $.ajax post to struts2 action returns Internal Server Error

查看:120
本文介绍了$ .ajax发布到struts2操作返回内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行此AJAX帖子,但收到服务器500错误.如果我不发送任何数据,我可以看到它达到了控制器中设置的断点.但是,当我发送数据时,它没有并返回500错误.帮助?谢谢.

I am trying to perform this AJAX post but getting a server 500 error. If I don't send any data i can see it hits break point set in the controller. But when I send data it doesnt and returns 500 error. help? Thanks.

在Firebug控制台中,
请求标头具有Content-Type application/x-www-form-urlencoded; charset=UTF-8 和响应为com.hearsay.example.mktpx.ui.action.LoadDefaultsAction.retrieveBenchmark()

In firebug console,
The request header has Content-Type application/x-www-form-urlencoded; charset=UTF-8 and Response as com.hearsay.example.mktpx.ui.action.LoadDefaultsAction.retrieveBenchmark()

代码:

$.ajax( {
    type : "POST",
    url : "loadBenchMark",
    data : {'ruleset':'1'},
    success : function(data) {
        console.log("success"); 
        },
            error:error : function(request, textStatus, errorThrown) {
        console.log("Error Thrown:"  +request.statusText); 
        }
 });

动作类:

  public String retrieveBenchmark(int ruleset) {
    setBenchmarkProductList(retrieveBenchmarkProductList());
    return SUCCESS;
}

Struts.xml

Struts.xml

<action name="loadBenchMark"
        class="com.hearsay.example.mktpx.ui.action.LoadDefaultsAction" method="retrieveBenchmark">
   <result type="json"></result>
</action>

推荐答案

首先,从方法中删除ruleset参数.然后,使用标准的getter和setter方法在操作类中添加实例变量,如下所示:

First, remove the ruleset parameter from the method. Then, add an instance variable instead in the action class, with standard getter and setter methods - like this:

private int ruleset // or String, if you're passing String values

public int getRuleset() {
   return this.ruleset;
}

public void setRuleset(int ruleset) {
   this.ruleset = ruleset;
}

这是将参数传递给Struts动作的方式-Struts将调用适当的setter.记住要使用正确的数据类型-不要为int变量等传递String值.

This is the way parameters are passed to a Struts action - Struts will call the appropriate setter. Remember to use correct data types - do not pass String values for int variables etc.

这篇关于$ .ajax发布到struts2操作返回内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆