{"id":818,"date":"2013-05-18T07:52:51","date_gmt":"2013-05-17T23:52:51","guid":{"rendered":"http:\/\/blog.amjet.cc\/IT\/?p=818"},"modified":"2014-10-23T10:10:19","modified_gmt":"2014-10-23T02:10:19","slug":"struts2-json-plugin","status":"publish","type":"post","link":"https:\/\/blog.amjet.biz\/IT\/?p=818","title":{"rendered":"Struts2 + JSON plugin"},"content":{"rendered":"<p>\u7c21\u55ae\u8a18\u9304 struts2 + json plugin \u7684 AJAX \u5beb\u6cd5<\/p>\n<p>1. \u5728 struts2 \u7684 xml \u6a94\u52a0\u5165\u4ee5\u4e0b json \u8a2d\u5b9a<\/p>\n<p>&lt;package name=&#8221;json&#8221; namespace=&#8221;\/json&#8221; extends=&#8221;json-default&#8221;&gt;<br \/>\n&lt;action name=&#8221;getCustomer&#8221; class=&#8221;com.amjet.web.action.JsonAction&#8221; method=&#8221;getCustomer&#8221;&gt;<br \/>\n&lt;result name=&#8221;success&#8221; type=&#8221;json&#8221;&gt;<br \/>\n&lt;param name=&#8221;root&#8221;&gt;response&lt;\/param&gt;<br \/>\n&lt;\/result&gt;<br \/>\n&lt;\/action&gt;<br \/>\n&lt;\/package&gt;<\/p>\n<p>2.\u00a0json action \u5167\u653e\u4e00\u500b property response, \u4f8b\u5982<\/p>\n<p>private Map&lt;String,Object&gt; response;<\/p>\n<p>\u52a0\u4e0a getter, setter, \u56de\u50b3 ajax response<\/p>\n<p>3.\u00a0json action method<\/p>\n<p>public String getCustomer() {<\/p>\n<p>response=new HashMap&lt;String,Object&gt;();<\/p>\n<p>response.put(&#8220;info&#8221;,&lt;customer info&gt;);<br \/>\nreturn SUCCESS;<br \/>\n}<\/p>\n<p>4. \u9801\u9762\u63a5\u53d6 json \u8cc7\u6599<\/p>\n<p>function doQuery() {<br \/>\n$.ajax({<br \/>\nurl: &#8216;&lt;s:url action=&#8221;getCustomer&#8221; namespace=&#8221;\/json&#8221;\/&gt;&#8217;,<br \/>\ntype: &#8216;POST&#8217;,<br \/>\ndataType: &#8216;json&#8217;,<br \/>\ndata: { id_no: id_no },<br \/>\nsuccess: function(data,status,xhr) {<\/p>\n<p>*** \u00a0your handler here ***<\/p>\n<p><em id=\"__mceDel\"> }<br \/>\n});<br \/>\n}<\/em><\/p>\n<p>[ratings]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7c21\u55ae\u8a18\u9304 struts2 + json plugin \u7684 AJAX \u5beb\u6cd5 1. \u5728 struts2 \u7684 xml \u6a94\u52a0\u5165\u4ee5\u4e0b json \u8a2d\u5b9a &lt;package name=&#8221;json&#8221; namespace=&#8221;\/json&#8221; extends=&#8221;json-default&#8221;&gt; &lt;action name=&#8221;getCustomer&#8221; class=&#8221;com.amjet.web.action.JsonAction&#8221; method=&#8221;getCustomer&#8221;&gt; &lt;result name=&#8221;success&#8221; type=&#8221;json&#8221;&gt; &lt;param name=&#8221;root&#8221;&gt;response&lt;\/param&gt; &lt;\/result&gt; &lt;\/action&gt; &lt;\/package&gt; 2.\u00a0json action \u5167\u653e\u4e00\u500b property response, \u4f8b\u5982 private Map&lt;String,Object&gt; response; \u52a0\u4e0a getter, setter, \u56de\u50b3 ajax response 3.\u00a0json action method public String getCustomer() { response=new [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,8],"tags":[119,33],"class_list":["post-818","post","type-post","status-publish","format-standard","hentry","category-ajax","category-java","tag-json","tag-struts2"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=\/wp\/v2\/posts\/818","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=818"}],"version-history":[{"count":3,"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=\/wp\/v2\/posts\/818\/revisions"}],"predecessor-version":[{"id":872,"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=\/wp\/v2\/posts\/818\/revisions\/872"}],"wp:attachment":[{"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=818"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=818"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}