In Action:
//Declaration
JSONObject jObj1 = null;
public JSONObject getjObj1() {
return jObj1;
}
public void setjObj1(JSONObject jObj1) {
this.jObj1 = jObj1;
}
//In Action method
String jsong="{\"cid\":232}";
jObj1 = new JSONObject(jsong);
return Action.SUCCESS
Struts Cfg File :
<action name="jsonAction" class="jsonAction" method="getJson">
<result type="json" name="success">
<param name="root">jObj1</param>
</result>
</action>
I am getting empty result when I see in JSP console
Where I went wrong? Thanks.
You are overcomplicating it :)
The Struts2-JSON-Plugin will serialize in JSON your Action's objects for you, so you don't need (and it's an error) to encode them by yourself.
Then, keeping your code and config as it is, just change the Action to:
//Declaration
Map<String,Integer> jObj1 = null;
/* Getter and Setter */
//In Action method
jObj1 = new HashMap<String,Integer>();
jObj1.put("cid",232);
return Action.SUCCESS
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With