{"id":2855,"date":"2018-06-10T16:01:36","date_gmt":"2018-06-10T08:01:36","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=2855"},"modified":"2018-06-10T16:01:36","modified_gmt":"2018-06-10T08:01:36","slug":"struts2-result-%e6%b3%a8%e8%a7%a3%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=2855","title":{"rendered":"Struts2 @Result \u6ce8\u89e3\u6559\u7a0b"},"content":{"rendered":"<p>\n\tStruts2 \u88ab\u79f0\u4e3a\u662f\u6f0f\u6d1e\u4e4b\u738b\uff0c\u8fd1\u5e74\u6765\u5df2\u88ab\u6240\u6709\u5927\u516c\u53f8\u6240\u629b\u5f03\uff0c\u8fde Apache \u81ea\u5df1\u4e5f\u653e\u5f03 Struts2 \u4e86\u3002\u4f46\u662f\u4e00\u4e9b\u8001\u9879\u76ee\u7528\u7684\u8fd8\u662f Struts2\u3002\u5728\u7ef4\u62a4\u8fd9\u4e9b\u8001\u9879\u76ee\u65f6\uff0c\u5c31\u4e0d\u5f97\u4e0d\u7528 Struts2 \u4e86\u3002\n<\/p>\n<p>\n\t\u5176\u4e2d Struts2 \u7684&nbsp;@Result \u6ce8\u89e3\u5728\u9879\u76ee\u4e2d\u5927\u91cf\u5b58\u5728\uff0c\u65b0\u6765\u7684\u6bd5\u4e1a\u751f\uff0c\u5bf9 Struts \u90fd\u4e0d\u600e\u4e48\u4e86\u89e3\u4e86\u3002\u6240\u4ee5\u6211\u8fd9\u91cc\u6574\u7406\u4e86\u4e00\u7bc7\u5173\u4e8e&nbsp;@Result \u6ce8\u89e3\u7684\u7528\u6cd5\u6559\u7a0b\uff0c\u5e0c\u671b\u80fd\u5bf9\u5927\u5bb6\u6709\u6240\u5e2e\u52a9\uff01\n<\/p>\n<p>\n\t@Result \u6ce8\u89e3\u7684\u4f5c\u7528\u5c31\u662f\u544a\u8bc9\u7a0b\u5e8f\u6211\u7684 Action \u8fd4\u56de\u4ec0\u4e48\uff01\u4e00\u822c\u53ef\u4ee5\u914d\u5408 @Action \u4e00\u8d77\u4f7f\u7528\uff0c\u4e5f\u53ef\u4ee5\u5355\u72ec\u4f7f\u7528\u3002\u76f8\u5f53\u4e8e struts.xml \u4e2d\u7684\u914d\u7f6e\u4fe1\u606f\u3002\n<\/p>\n<p>\n\t\u4f8b\u5982\u4e0b\u9762\u7684\u914d\u7f6e\uff1a\n<\/p>\n<pre class=\"brush:java;\">\r\n@Action(value=&quot;save-task&quot;,results={@Result(name=SUCCESS, type=&quot;chain&quot;,location=&quot;add-task&quot;)})<\/pre>\n<p>\n\t\u4e5f\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u7684\u914d\u7f6e\uff1a\n<\/p>\n<pre class=\"brush:java;\">\r\n@Results={\r\n\t@Result(name=&quot;success&quot;,location=&quot;\/usersuc.jsp&quot;),\r\n\t@Result(name=&quot;error&quot;,location=&quot;\/usererror.jsp&quot;)\r\n}<\/pre>\n<p>\n\t\u4e0a\u9762\u7b2c\u4e00\u4e2a\u5217\u4e3e\u7684 type \u662f\u8df3\u8f6c\u7c7b\u578b\u3002\u4e00\u822c\u5305\u542b\u5982\u4e0b\u51e0\u4e2a\u503c\uff1a\n<\/p>\n<ul>\n<li>\n\t\tredirect:action\u5904\u7406\u5b8c\u540e\u91cd\u5b9a\u5411\u5230\u4e00\u4e2a\u89c6\u56fe\u8d44\u6e90\uff08\u5982\uff1ajsp\u9875\u9762\uff09\uff0c\u8bf7\u6c42\u53c2\u6570\u5168\u90e8\u4e22\u5931\uff0caction\u5904\u7406\u7ed3\u679c\u4e5f\u5168\u90e8\u4e22\u5931\u3002\n\t<\/li>\n<li>\n\t\tredirect-action:action\u5904\u7406\u5b8c\u540e\u91cd\u5b9a\u5411\u5230\u4e00\u4e2aaction\uff0c\u8bf7\u6c42\u53c2\u6570\u5168\u90e8\u4e22\u5931\uff0caction\u5904\u7406\u7ed3\u679c\u4e5f\u5168\u90e8\u4e22\u5931\u3002\n\t<\/li>\n<li>\n\t\tchain:action\u5904\u7406\u5b8c\u540e\u8f6c\u53d1\u5230\u4e00\u4e2aaction\uff0c\u8bf7\u6c42\u53c2\u6570\u4e0d\u4f1a\u4e22\u5931\uff0caction\u5904\u7406\u7ed3\u679c\u4e0d\u4f1a\u4e22\u5931\n\t<\/li>\n<li>\n\t\tdispatcher \u4e3a\u9ed8\u8ba4\u8df3\u8f6c\u7c7b\u578b\uff0c\u7528\u4e8e\u8fd4\u56de\u4e00\u4e2a\u89c6\u56fe\u8d44\u6e90(\u5982:jsp)\n\t<\/li>\n<li>\n\t\tjson \u8fd4\u56dejson\u6570\u636e\n\t<\/li>\n<\/ul>\n<pre class=\"brush:java;\">\r\n@ParentPackage(&quot;json-default&quot;)  \r\n@Results({ @Result(name = &quot;jsonExample&quot;, type = &quot;json&quot;) })  \r\npublic class JsonExampleAction {  \r\n    private String result;  \r\n    private String type;  \r\n  \r\n    @Action(value = &quot;\/json\/jsonExample&quot;)  \r\n    public String jsonExample() {  \r\n        if (&quot;json&quot;.equals(type)) {  \r\n            result = &quot;json&quot;;  \r\n        } else {  \r\n            result = &quot;other&quot;;  \r\n        }  \r\n        return &quot;jsonExample&quot;;  \r\n    }  <\/pre>\n<p>\n\tname \u5c31\u662f\u6267\u884c\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u3002location \u5c31\u662f\u8df3\u8f6c\u7684\u94fe\u63a5\u3002type \u662f\u8df3\u8f6c\u8fd4\u56de\u7c7b\u578b\u5427\u3002\u5982\u4e0a\u9762\u5217\u4e3e\u7684\u793a\u4f8b\u3002\n<\/p>\n<p>\n\t\u4e0a\u9762\u7684\u914d\u7f6e\u76f8\u5f53\u4e8e struts.xml \u4e2d\u7684\u4e0b\u9762\u7684\u914d\u7f6e\uff1a\n<\/p>\n<pre class=\"brush:java;\">\r\n&lt;result name=&quot;err&quot; type=&quot;plaintext&quot;&gt;\r\n\t&lt;param name=&quot;location&quot;&gt;\u5177\u4f53\u7684\u4f4d\u7f6e&lt;\/param&gt;\r\n\t&lt;param name=&quot;charSet&quot;&gt;\u5b57\u7b26\u89c4\u8303(\u5982GBK)&lt;\/param&gt;\r\n&lt;\/result&gt;<\/pre>\n<p>\n\t\u73b0\u5728\u6ce8\u89e3\u5927\u884c\u5176\u9053\uff0c\u6240\u4ee5\u5404\u79cdxml\u5c31\u8981\u5c11\u7528\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=2855\">Struts2 @Result \u6ce8\u89e3\u6559\u7a0b<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>Struts2 \u88ab\u79f0\u4e3a\u662f\u6f0f\u6d1e\u4e4b\u738b\uff0c\u8fd1\u5e74\u6765\u5df2\u88ab\u6240\u6709\u5927\u516c\u53f8\u6240\u629b\u5f03\uff0c\u8fde Apache \u81ea\u5df1\u4e5f\u653e\u5f03 Struts2 \u4e86 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[992,99,210,101,1045],"class_list":["post-2855","post","type-post","status-publish","format-standard","hentry","category-java","tag-shiro-","tag-struts2","tag-1045"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2855","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2855"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2855\/revisions"}],"predecessor-version":[{"id":2856,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2855\/revisions\/2856"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2855"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2855"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2855"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}