开发者

$.ajax post to struts2 action returns Internal Server Error

开发者 https://www.devze.com 2023-02-21 00:01 出处:网络
I am trying to perform this AJAX postbut 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

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.

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()

Code :

$.ajax( {
    type : "POST",
    url : "loadBenchMark",
    data : {'ruleset':'1'},
    success : function(data) {
        console.log("success"); 
        },
            error:error : function(request, textStatus, errorThrown) {
        console.log("Error Throw开发者_StackOverflow中文版n:"  +request.statusText); 
        }
 });

Action Class:

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

Struts.xml

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


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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消