0

I have used JSONObject json = (JSONObject)new JSONParser().parse(jb.toString()); for getting json object in servlet and JSONObject result=new JSONObject();response.getWriter().write(result.toString()); for posting json object. But i have no idea how to do this in struts 2.0.

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
Ronak Joshi
  • 1,553
  • 2
  • 20
  • 43
  • DO NOT USE STRUTS 2.0. Use 2.3.16.3 – Andrea Ligios Nov 21 '14 at 08:39
  • There is S2 json plugin: http://struts.apache.org/release/2.3.x/docs/json-plugin.html. – Aleksandr M Nov 21 '14 at 08:39
  • http://stackoverflow.com/a/17149414/1654265 – Andrea Ligios Nov 21 '14 at 08:40
  • I have to use Struts 2.0 framework. Can you give me that type of example which can describe json getting and posting in single action class. @AndreaLigios – Ronak Joshi Nov 21 '14 at 09:07
  • Then fight for using Struts 2.3.16.3. Struts 2.0 is not only very old and bugged, it has some really serious security problems. Noone should ever use it anymore. Ask your PM what's the problem in migrating to 2.3 for new projects, and remind him that when a disaster will occour, it will be his fault. Be sure to get the order of using 2.0 in a mail, and keep it. P.S: first drawback: JSON Plugin is available since 2.1, IIRC. – Andrea Ligios Nov 21 '14 at 09:12

2 Answers2

2

You need the Json Plug in. This plug in will be able to parse your action response into a JSON automatically and the interceptors will store your request into your action.

You have an example with Struts2 with annotations and datatables here

PbxMan
  • 7,525
  • 1
  • 36
  • 40
1

String "str" have Json message who extract json in action using key value pair example to more understanding...

JSONObject json = new JSONObject(str);
        rec_id = json.getInt("receptionist_id");
        tag_id = json.getInt("tag_id");