Return JSON response to ajax from struts action -


i calling struts action using ajax. javascript code below

$.ajax({                 url: '${pagecontext.request.contextpath}/gettransactiondata.do',                 type: 'post',                      success: function(data)                     {                                  alert(data);                      },                 error: function(xmlhttprequest, textstatus, errorthrown){                 alert('error ' + textstatus);                 alert(errorthrown);                 alert(xmlhttprequest.responsetext);                 }     }); 

i have written action class in want create list of data , access data in jsp page json response.

action class method

public actionforward execute(actionmapping mapping, actionform form,             httpservletrequest request, httpservletresponse response)                     throws exception     {                list<map> datalist = new arraylist<>();             map<string, object> datamap = new hashmap<string, object>();              datamap.put("name", "testname");             datamap.put("age", 20);              datalist.add(datamap);              system.out.println(datalist);              string data = new gson().tojson(datalist);              system.out.println(data);             //                     response.getoutputstream().write(data.getbytes());              return mapping.findforward(constants.success);      } 

struts-config.xml

<action path="/gettransactiondata"  type="com.tests.elasticquery" >           <forward name="success" path="/jsp/pp/dashboardreport.jsp" />  </action> 

how can json response dashboardreport.jsp , other thing when put response.getoutputstream().write(data.getbytes()); line of code in action class method action not invoked (it gives not found error 404) , if remove action invoked normally. why ? appreciated


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -