{"id":1650,"date":"2018-06-06T11:01:38","date_gmt":"2018-06-06T03:01:38","guid":{"rendered":"http:\/\/www.netxintai.com\/?p=1650"},"modified":"2024-12-01T09:52:25","modified_gmt":"2024-12-01T01:52:25","slug":"struts2%e6%95%99%e7%a8%8b-%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/www.netxintai.com\/?p=1650","title":{"rendered":"struts2\u6559\u7a0b-\u914d\u7f6e\u6587\u4ef6\u8be6\u89e3"},"content":{"rendered":"<p style=\"white-space: normal;\">&nbsp; &nbsp; &nbsp; &nbsp; \u9996\u5148\u6211\u4eec\u6765\u770b\u4e0bstruts2\u7684\u6267\u884c\u8fc7\u7a0b<\/p>\n<p style=\"white-space: normal;\"><img decoding=\"async\" src=\"http:\/\/www.netxintai.com\/ueditor\/php\/upload\/image\/20180606\/1528250383488565.jpg\" title=\"1528250383488565.jpg\" alt=\"struts2\u6267\u884c\u8fc7\u7a0b.jpg\"\/><\/p>\n<p style=\"white-space: normal;\">\u5982\u679c\u5404\u4f4d\u6709\u5174\u8da3\u7684\u8bdd\u53ef\u4ee5\u53bb\u67e5\u770b\u4e0bStruts2\u7684\u6e90\u7801\uff0c\u8fd9\u91cc\u6211\u53ea\u8d34\u51fa&nbsp;StrutsPrepareAndExecuteFilter \u8fd9\u4e2a\u8fc7\u6ee4\u5668\u5728\u4e2d\u7684inti\u65b9\u6cd5<\/p>\n<pre class=\"brush:java;toolbar:false\">public&nbsp;class&nbsp;StrutsPrepareAndExecuteFilter&nbsp;implements&nbsp;StrutsStatics,&nbsp;Filter&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;protected&nbsp;PrepareOperations&nbsp;prepare;\r\n&nbsp;&nbsp;&nbsp;&nbsp;protected&nbsp;ExecuteOperations&nbsp;execute;\r\n&nbsp;&nbsp;&nbsp;&nbsp;protected&nbsp;List&lt;Pattern&gt;&nbsp;excludedPatterns&nbsp;=&nbsp;null;\r\n\r\n&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;init(FilterConfig&nbsp;filterConfig)&nbsp;throws&nbsp;ServletException&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InitOperations&nbsp;init&nbsp;=&nbsp;new&nbsp;InitOperations();\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dispatcher&nbsp;dispatcher&nbsp;=&nbsp;null;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FilterHostConfig&nbsp;config&nbsp;=&nbsp;new&nbsp;FilterHostConfig(filterConfig);\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;init.initLogging(config);\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dispatcher&nbsp;=&nbsp;init.initDispatcher(config);\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;init.initStaticContentLoader(config,&nbsp;dispatcher);\r\n\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prepare&nbsp;=&nbsp;new&nbsp;PrepareOperations(dispatcher);\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;execute&nbsp;=&nbsp;new&nbsp;ExecuteOperations(dispatcher);\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.excludedPatterns&nbsp;=&nbsp;init.buildExcludedPatternsList(dispatcher);\r\n\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;postInit(dispatcher,&nbsp;filterConfig);\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;finally&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(dispatcher&nbsp;!=&nbsp;null)&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dispatcher.cleanUpAfterInit();\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;init.cleanup();\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\r\n&nbsp;&nbsp;&nbsp;&nbsp;}<\/pre>\n<p style=\"white-space: normal;\">\u6839\u636e\u4ee3\u7801\u5b9e\u73b0\u8fc7\u6ee4\u5668\u5728\u670d\u52a1\u5668\u542f\u52a8\u7684\u65f6\u5019\u521b\u5efa\uff0c\u521b\u5efa\u8fc7\u6ee4\u5668\u7684\u65f6\u5019\u6267\u884cinit\u65b9\u6cd5\uff0c\u5728init\u65b9\u6cd5\u4e2d\u4e3b\u8981\u52a0\u8f7d\u914d\u7f6e\u6587\u4ef6\uff0c\u5305\u542b\u81ea\u5df1\u521b\u5efa\u7684\u914d\u7f6e\u6587\u4ef6\u548cstruts2\u81ea\u5e26\u914d\u7f6e\u6587\u4ef6struts.xml&nbsp;<\/p>\n<p style=\"white-space: normal;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>&nbsp;<span style=\"font-size: 20px;\">Struts2\u914d\u7f6e\u8be6\u89e3<\/span><\/strong><\/p>\n<p style=\"white-space: normal;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;1\u3001&nbsp;struts2\u7684\u6838\u5fc3\u914d\u7f6e\u6587\u4ef6\u7684\u540d\u79f0\u548c\u4f4d\u7f6e\u662f\u56fa\u5b9a\u7684\uff0c\u4f4d\u7f6e\u53ea\u80fd\u5b58\u653e\u5728src\u4e0b\u9762\uff0c\u540d\u79f0\u56fa\u5b9a\u4e3astruts.xml\u3002<\/p>\n<p style=\"white-space: normal;\"><img decoding=\"async\" src=\"http:\/\/www.netxintai.com\/ueditor\/php\/upload\/image\/20180606\/1528252060152037.png\" title=\"1528252060152037.png\" alt=\"image.png\"\/><\/p>\n<p style=\"white-space: normal;\">1\u3001struts.xml\u6587\u4ef6\u5185\u5bb9<\/p>\n<pre class=\"brush:xml;toolbar:false\">&lt;?xml&nbsp;version=&quot;1.0&quot;&nbsp;encoding=&quot;UTF-8&quot;&nbsp;?&gt;\r\n&lt;!DOCTYPE&nbsp;struts&nbsp;PUBLIC\r\n\t&quot;-\/\/Apache&nbsp;Software&nbsp;Foundation\/\/DTD&nbsp;Struts&nbsp;Configuration&nbsp;2.3\/\/EN&quot;\r\n\t&quot;http:\/\/struts.apache.org\/dtds\/struts-2.3.dtd&quot;&gt;\r\n\r\n&lt;struts&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;package&nbsp;name=&quot;default&quot;&nbsp;namespace=&quot;\/&quot;&nbsp;extends=&quot;struts-default&quot;&gt;\r\n&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;action&nbsp;name=&quot;userAction&quot;&nbsp;class=&quot;com.netxintai.action.UserAction&quot;&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;\t&lt;result&nbsp;name=&quot;login&quot;&gt;\/index.jsp&lt;\/result&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/action&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/package&gt;\r\n\r\n&lt;\/struts&gt;<\/pre>\n<p style=\"white-space: normal;\">&nbsp; &nbsp;\u914d\u7f6e\u6587\u4ef6\u4e2d\u4e3b\u8981\u6709\u4e09\u4e2a\u6807\u7b7e\u5206\u522b\u662f: package\u3001action\u548cresult<\/p>\n<p style=\"white-space: normal;\"><\/p>\n<p style=\"white-space: normal;\"><span style=\"font-family: arial, helvetica, sans-serif;\">&nbsp;&nbsp;\u6807\u7b7e package<\/span><\/p>\n<p style=\"white-space: normal;\"><span style=\"font-family: arial, helvetica, sans-serif;\">&nbsp;&nbsp;&nbsp;&nbsp;1\u3001\u7c7b\u4f3c\u4e8e\u4ee3\u7801\u5305\uff0c\u533a\u522b\u4e0d\u540c\u7684action \u8981\u914d\u7f6eaction \u9996\u5148\u5199pagckage\u6807\u7b7e\uff0c\u5728package\u91cc\u9762\u624d\u80fd\u914d\u7f6eaction<br \/><\/span><\/p>\n<p style=\"white-space: normal;\"><span style=\"font-family: arial, helvetica, sans-serif;\">&nbsp; &nbsp; 2\u3001package\u6807\u7b7e\u5c5e\u6027<\/span><\/p>\n<p style=\"white-space: normal;\"><span style=\"font-family: arial, helvetica, sans-serif;\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\u4e00\u3001name\u5c5e\u6027\uff1a\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6\u53ef\u4ee5\u5199\u591a\u4e2apackage\u6807\u7b7e\uff0cname\u5c5e\u6027\u7528\u4e8e\u533a\u5206\u4e0d\u540c\u7684package\uff0c\u6bcf\u4e2aname\u5c5e\u6027\u503c\u4e0d\u80fd\u76f8\u540c<\/span><\/p>\n<p style=\"white-space: normal;\"><span style=\"font-family: arial, helvetica, sans-serif;\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\u4e8c\u3001extends\u5c5e\u6027\uff1a\u5c5e\u6027\u503c\u56fa\u5b9a\u4e3a struts-default \u6709\u4e86\u8fd9\u4e2a\u5c5e\u6027\u4e4b\u540e\uff0c\u5728package\u91cc\u9762\u914d\u7f6e\u7684\u7c7b\u5177\u6709action\u529f\u80fd&nbsp; extends=&quot;struts-default&quot;<\/span><\/p>\n<p style=\"white-space: normal;\"><span style=\"font-family: arial, helvetica, sans-serif;\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\u4e09\u3001namespace\u5c5e\u6027\uff1a\u4e0eaction\u6807\u7b7e\u91cc\u9762\u7684name\u5c5e\u6027\u503c\u6784\u6210\u8bbf\u95ee\u8def\u5f84&nbsp; namespace=&quot;\/&quot;<\/span><\/p>\n<p style=\"white-space: normal;\"><span style=\"font-family: arial, helvetica, sans-serif;\">&nbsp; &nbsp;action\u6807\u7b7e<\/span><\/p>\n<p style=\"white-space: normal;\"><span style=\"font-family: arial, helvetica, sans-serif;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 name\u5c5e\u6027 \uff1a\u4e00\u3001namespace\u5c5e\u6027\u503c\u548caction\u548c\u6807\u7b7e\u91cc\u9762\u7684name\u5c5e\u6027\u503c\u6784\u6210\u8bbf\u95ee\u8def\u5f84 \u4f8b\u5982http:\/\/localhost:8080\/day01<span style=\"color: rgb(255, 0, 0);\">\/userAction&nbsp;<span style=\"color: rgb(0, 0, 0);\">\u7ea2\u8272\u5b57&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \u4f53\u90e8\u5206\u5c31\u662fpackage\u4e2d\u7684nameespace=&quot;\/&quot;\u548caction\u6807\u7b7e\u4e2d\u7684name=&quot;userAction&quot;\u6784\u6210\u7684<\/span><\/span><br \/><\/span><\/p>\n<p style=\"white-space: normal;\"><span style=\"color: rgb(255, 0, 0); font-family: arial, helvetica, sans-serif;\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\u4e8c\u3001\u5728package\u6807\u7b7e\u91cc\u9762\u53ef\u4ee5\u5199\u591a\u4e2aaction\u6807\u7b7e\uff0c\u4f46\u662faction\u7684name\u5c5e\u6027\u503c\u4e0d\u80fd\u76f8\u540c<\/span><\/p>\n<p style=\"white-space: normal;\"><span style=\"color: rgb(255, 0, 0); font-family: arial, helvetica, sans-serif;\">&nbsp; &nbsp; &nbsp; 2 class \u5c5e\u6027 \uff1aAction\u7684\u5168\u8def\u5f84\uff1b&nbsp;class=&quot;com.netxintai.action.UserAction&quot;<\/span><\/p>\n<p style=\"white-space: normal;\"><span style=\"font-family: arial, helvetica, sans-serif;\">&nbsp; &nbsp; &nbsp; 3 method\u5c5e\u6027 : \u8ba9\u4e00\u4e2aaction\u53ef\u4ee5\u6267\u884c\u591a\u4e2a\u65b9\u6cd5\u3002method=&quot;{1}&quot;&nbsp; &nbsp; <br \/><\/span><\/p>\n<p style=\"white-space: normal;\"><span style=\"font-family: arial, helvetica, sans-serif;\">&nbsp; &nbsp;result \u6807\u7b7e&nbsp; \u6839\u636eaction\u4e2d\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\uff0c\u914d\u7f6e\u5230\u4e0d\u540c\u7684\u8def\u5f84\u91cc\u9762<\/span><\/p>\n<p style=\"white-space: normal;\"><span style=\"font-family: arial, helvetica, sans-serif;\">&nbsp; &nbsp; &nbsp; &nbsp;1 name\u5c5e\u6027\uff1a\u5fc5\u987b\u548c\u65b9\u6cd5\u8fd4\u56de\u503c\u4e00\u6837\uff0c\u5426\u5219\u65e0\u6cd5\u627e\u5230\u8def\u5f84<\/span><\/p>\n<p style=\"white-space: normal;\"><span style=\"font-family: arial, helvetica, sans-serif;\">&nbsp; &nbsp; &nbsp; &nbsp;2 type\u5c5e\u6027\uff1a\u914d\u7f6e\u4e3a\u8f6c\u53d1\u6216\u8005\u91cd\u5b9a\u5411\u5c5e\u6027 \u9ed8\u8ba4\u662f\u8f6c\u53d1\u64cd\u4f5c<\/span><\/p>\n<p style=\"white-space: normal;\">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<\/p>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; &nbsp; &nbsp; &nbsp; \u9996\u5148\u6211\u4eec\u6765\u770b\u4e0bstruts2\u7684\u6267\u884c\u8fc7\u7a0b \u5982\u679c\u5404\u4f4d\u6709\u5174\u8da3 <span class=\"ellipsis\">&hellip;<\/span> <span class=\"more-link-wrap\"><a href=\"https:\/\/www.netxintai.com\/?p=1650\" class=\"more-link\"><span>Read More &rarr;<\/span><\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":1491,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[50],"tags":[110,165],"_links":{"self":[{"href":"https:\/\/www.netxintai.com\/index.php?rest_route=\/wp\/v2\/posts\/1650"}],"collection":[{"href":"https:\/\/www.netxintai.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.netxintai.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.netxintai.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.netxintai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1650"}],"version-history":[{"count":1,"href":"https:\/\/www.netxintai.com\/index.php?rest_route=\/wp\/v2\/posts\/1650\/revisions"}],"predecessor-version":[{"id":1651,"href":"https:\/\/www.netxintai.com\/index.php?rest_route=\/wp\/v2\/posts\/1650\/revisions\/1651"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.netxintai.com\/index.php?rest_route=\/wp\/v2\/media\/1491"}],"wp:attachment":[{"href":"https:\/\/www.netxintai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.netxintai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1650"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.netxintai.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}