struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephan Schreck <>
Subject json data are not passed in Stuts action
Date Wed, 21 Nov 2012 15:46:54 GMT
i have a problem with my struts 2 application. I try to send some json 
data in my action from the following

                 $(document).ready(function () {

                var data = {data: {jsonKey1 : "one", jsonKey2: "two", 
jsonKey3: [1, 2, 3, 4, 5], jsonKey4: {a: "A", b: 2, c: "3"}, jsonKey5: 
2, jsonKey6: "2"}};
                         type: "POST",
                         url: "http://localhost:8080/myAction",
                         data: jQuery.toJSON(data),
                         dataType: "json",
                         async: false ,
                         contentType: "application/json; charset=utf-8",
                         success: function(){window.alert("Done");}

The action is called without any problem. What i am trying to achieve is 
to send the data to my action and set the Map data. This is something
that does not work.  In my struts.xml i have included the 
JSONInterceptor in my stack, as seen below:

                 <interceptor-ref name="scopedModelDriven" />
                 <interceptor-ref name="modelDriven" />
                 <interceptor-ref name="fileUpload" />
                 <interceptor-ref name="json" />
                 <interceptor-ref name="staticParams" />
                 <interceptor-ref name="actionMappingParams" />

                 <interceptor-ref name="params">

Here the action that is called while the script is running.

@Result(name = "success", type = "json")
public class MyAction extends BaseAction {

     Map data = new HashMap();

     public String execute() throws Exception {

         return SUCCESS;

     public Map getData() {
         return data;

     public void setData(Map data) { = data;

I have added some brakepoints in  the JSONInterceptor. In there there is 
a variable String contentType = request.getHeader("content-type");
The variable contentType seems to be always null. So maybe that is where 
the problem starts from. The data sent are not
recognized as json data maybe.

All in all and in a few lines, i am trying to send the data from the 
script to my struts Action but it seems that i am missing something

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message