{"id":768,"date":"2013-03-07T19:37:27","date_gmt":"2013-03-07T11:37:27","guid":{"rendered":"http:\/\/blog.amjet.cc\/IT\/?p=768"},"modified":"2014-10-23T10:12:26","modified_gmt":"2014-10-23T02:12:26","slug":"struts2-tips","status":"publish","type":"post","link":"https:\/\/blog.amjet.biz\/IT\/?p=768","title":{"rendered":"Struts2 tips"},"content":{"rendered":"<p>\u7576 struts2 \u7684 action code \u62cb\u51fa exception \u6642\uff0c\u6709\u4e00\u500b\u9801\u9762\u63d0\u793a\u7cfb\u7d71\u7684\u4f7f\u7528\u8005\u662f\u76f8\u7576\u65b9\u4fbf\u7684\uff0c\u4e00\u65b9\u9762\u8b93\u4f7f\u7528\u8005\u4e86\u89e3\u76ee\u524d\u767c\u751f\u4e86\u7570\u5e38\u7684\u60c5\u5f62\uff0c\u4e5f\u53ef\u4ee5\u5728\u9801\u9762\u4e0a\u7f6e\u5165\u932f\u8aa4\u78bc\u8b93\u554f\u984c\u56de\u5831\u53ca\u89e3\u6c7a\u66f4\u52a0\u6709\u6548\u7387\u3002\u672c\u6587\u4e3b\u8981\u53c3\u8003\u9019\u500b <a href=\"http:\/\/struts.apache.org\/release\/2.0.x\/docs\/exception-configuration.html\" target=\"_blank\">\u7db2\u5740<\/a><\/p>\n<p>\u9996\u5148\u5728 struts.xml \u8981\u6709\u4ee5\u4e0b\u8a2d\u5b9a<\/p>\n<p>&lt;global-results&gt;<br \/>\n&lt;result name=&#8221;Exception&#8221;&gt;\/Exception.jsp&lt;\/result&gt;<br \/>\n&lt;\/global-results&gt;<br \/>\n&lt;global-exception-mappings&gt;<br \/>\n&lt;exception-mapping exception=&#8221;java.lang.Exception&#8221; result=&#8221;Exception&#8221;\/&gt;<br \/>\n&lt;\/global-exception-mappings&gt;<\/p>\n<p>\u5728 jsp \u53ef\u4ee5\u986f\u793a &#8216;\u76ee\u524d\u7cfb\u7d71\u767c\u751f\u7570\u5e38\u72c0\u6cc1\uff0c\u932f\u8aa4\u4ee3\u78bc\u70ba xxxxxx\u00a0\uff0c\u8acb\u5411\u7cfb\u7d71\u7ba1\u7406\u4eba\u54e1\u56de\u5831\u4ee5\u4fbf\u5118\u5feb\u8655\u7406&#8217; \u3002<\/p>\n<p>\u53e6\u5916\u5728 jsp \u7684 OGNL \u8a9e\u6cd5\u5b57\u4e32\u6bd4\u8f03\u90e8\u4efd\u6709\u4e00\u500b\u5c0f\u63d0\u793a<\/p>\n<p>&lt;s:if test=&#8221;%{#request.err_code.equals(&#8216;A&#8217;)&#8221;&gt;<\/p>\n<p>\u9019\u500b\u5beb\u6cd5 err_code \u662f\u5b57\u4e32\uff0c&#8217;A&#8217; \u662f\u4e00\u500b character\uff0c\u6240\u4ee5\u5373\u4f7f action err_code \u50b3\u4f86 &#8220;A&#8221;\uff0c\u6bd4\u5c0d\u7684\u7d50\u679c\u4ecd\u7136\u662f false<\/p>\n<p>&lt;s:if test=&#8217;%{#request.err_code.equals(&#8220;A&#8221;)&#8217;&gt;<\/p>\n<p>\u4ee5\u4e0a\u7684\u5beb\u6cd5\u6bd4\u5c0d\u7684\u7d50\u679c\u624d\u6703\u662f true<\/p>\n<p>&nbsp;<\/p>\n<p>[ratings]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7576 struts2 \u7684 action code \u62cb\u51fa exception \u6642\uff0c\u6709\u4e00\u500b\u9801\u9762\u63d0\u793a\u7cfb\u7d71\u7684\u4f7f\u7528\u8005\u662f\u76f8\u7576\u65b9\u4fbf\u7684\uff0c\u4e00\u65b9\u9762\u8b93\u4f7f\u7528\u8005\u4e86\u89e3\u76ee\u524d\u767c\u751f\u4e86\u7570\u5e38\u7684\u60c5\u5f62\uff0c\u4e5f\u53ef\u4ee5\u5728\u9801\u9762\u4e0a\u7f6e\u5165\u932f\u8aa4\u78bc\u8b93\u554f\u984c\u56de\u5831\u53ca\u89e3\u6c7a\u66f4\u52a0\u6709\u6548\u7387\u3002\u672c\u6587\u4e3b\u8981\u53c3\u8003\u9019\u500b \u7db2\u5740 \u9996\u5148\u5728 struts.xml \u8981\u6709\u4ee5\u4e0b\u8a2d\u5b9a &lt;global-results&gt; &lt;result name=&#8221;Exception&#8221;&gt;\/Exception.jsp&lt;\/result&gt; &lt;\/global-results&gt; &lt;global-exception-mappings&gt; &lt;exception-mapping exception=&#8221;java.lang.Exception&#8221; result=&#8221;Exception&#8221;\/&gt; &lt;\/global-exception-mappings&gt; \u5728 jsp \u53ef\u4ee5\u986f\u793a &#8216;\u76ee\u524d\u7cfb\u7d71\u767c\u751f\u7570\u5e38\u72c0\u6cc1\uff0c\u932f\u8aa4\u4ee3\u78bc\u70ba xxxxxx\u00a0\uff0c\u8acb\u5411\u7cfb\u7d71\u7ba1\u7406\u4eba\u54e1\u56de\u5831\u4ee5\u4fbf\u5118\u5feb\u8655\u7406&#8217; \u3002 \u53e6\u5916\u5728 jsp \u7684 OGNL \u8a9e\u6cd5\u5b57\u4e32\u6bd4\u8f03\u90e8\u4efd\u6709\u4e00\u500b\u5c0f\u63d0\u793a &lt;s:if test=&#8221;%{#request.err_code.equals(&#8216;A&#8217;)&#8221;&gt; \u9019\u500b\u5beb\u6cd5 err_code \u662f\u5b57\u4e32\uff0c&#8217;A&#8217; \u662f\u4e00\u500b character\uff0c\u6240\u4ee5\u5373\u4f7f action err_code \u50b3\u4f86 &#8220;A&#8221;\uff0c\u6bd4\u5c0d\u7684\u7d50\u679c\u4ecd\u7136\u662f false &lt;s:if test=&#8217;%{#request.err_code.equals(&#8220;A&#8221;)&#8217;&gt; \u4ee5\u4e0a\u7684\u5beb\u6cd5\u6bd4\u5c0d\u7684\u7d50\u679c\u624d\u6703\u662f true &nbsp; [ratings]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[121,33],"class_list":["post-768","post","type-post","status-publish","format-standard","hentry","category-java","tag-exception","tag-struts2"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=\/wp\/v2\/posts\/768","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=768"}],"version-history":[{"count":4,"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=\/wp\/v2\/posts\/768\/revisions"}],"predecessor-version":[{"id":785,"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=\/wp\/v2\/posts\/768\/revisions\/785"}],"wp:attachment":[{"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=768"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=768"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=768"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}