需要的jar包::
struts.xml中配置:
<package name="test1" extends="
json-default" namespace="/test1">
<action name="test_*" class="com.pmg.TestAction" method="{1}">
<result name="success" type=
"json">
<param name="root">
map</param>
序列化 json格式
</result>
</action>
</package>
action:
private Map<Integer, String>
map = new HashMap<Integer, String>();
public Map<Integer, String> getMap() {
return map;
}
public void setMap(Map<Integer, String> map) {
this.map = map;
}
public String index()
{
for(int i=1;i<5;i++)
{
map.put(i,"xhmz"+i);
}
return "success";
}