{"id":1846,"date":"2016-12-28T15:03:29","date_gmt":"2016-12-28T07:03:29","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=1846"},"modified":"2026-08-18T11:19:31","modified_gmt":"2026-08-18T03:19:31","slug":"%e6%b7%b1%e5%85%a5%e4%ba%86%e8%a7%a3struts2","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=1846","title":{"rendered":"\u6df1\u5165\u4e86\u89e3Struts2"},"content":{"rendered":"<section id=\"wenyan\" style=\"font-family: system-ui, 'Apple Color Emoji', 'Segoe UI', 'Segoe UI Symbol', 'Noto Sans', Roboto, sans-serif; line-height: 1.75; font-size: 16px; color: #000000; caret-color: #000000;\" data-provider=\"WenYan\">\n<p style=\"margin: 1em 0px;\">\u628a Struts2 \u7528\u719f\u7ec3\uff0c\u65e5\u5e38\u56f4\u7740\u4e24\u4efd\u6587\u4ef6\u8f6c\uff1a<strong style=\"color: #4870ac;\">struts.properties<\/strong> \u7ba1\u5e38\u91cf\uff0c<strong style=\"color: #4870ac;\">struts.xml<\/strong> \u7ba1 package \/ action \/ result\u3002\u8fd9\u4e24\u4efd\u8bfb\u660e\u767d\uff0c\u52a8\u6001\u65b9\u6cd5\u8c03\u7528\u548c\u53c2\u6570\u7ed1\u5b9a\u624d\u4e0d\u4f1a\u6655\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u4e0b\u9762\u6309\u539f\u7b14\u8bb0\u5f80\u4e0b\u8d70\uff1a\u6838\u5fc3\u6587\u4ef6 \u2192 Action \u6309\u547d\u540d\u7a7a\u95f4\u5f80\u4e0a\u641c\u7684\u987a\u5e8f \u2192 \u4e09\u79cd\u52a8\u6001\u65b9\u6cd5\u8c03\u7528 \u2192 \u4e09\u79cd\u6536\u53c2\u6570\u65b9\u5f0f\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e00\u3001struts \u6838\u5fc3\u6587\u4ef6<\/h2>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">1. struts.properties \u5e38\u91cf<\/h3>\n<p style=\"margin: 1em 0px;\">\u5f00\u53d1\u671f\u5e38\u7528\u7684\u5e38\u91cf\u53ef\u4ee5\u5199\u5728 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">struts.properties<\/code>\uff0c\u4e5f\u53ef\u4ee5\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">&lt;constant&gt;<\/code> \u5199\u8fdb struts.xml\uff0c\u6548\u679c\u4e00\u6837\u3002<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">#\u662f\u5426\u5f00\u542f\u5f00\u53d1\u6a21\u5f0f\nstruts.devMode=true\n#\u6240\u6709\u5339\u914d *.action \u7684\u8bf7\u6c42\u90fd\u7531 struts2 \u5904\u7406\nstruts.action.extension=do\n#struts \u914d\u7f6e\u6587\u4ef6\u6539\u52a8\u540e\uff0c\u662f\u5426\u91cd\u65b0\u52a0\u8f7d\nstruts.configuration.xml.reload=true\n#\u8bf7\u6c42\u53c2\u6570\u7684\u7f16\u7801\u65b9\u5f0f\nstruts.i18n.encoding=UTF-8\n#\u6bcf\u6b21 HTTP \u8bf7\u6c42\u7cfb\u7edf\u90fd\u91cd\u65b0\u52a0\u8f7d\u8d44\u6e90\u6587\u4ef6\uff0c\u6709\u52a9\u4e8e\u5f00\u53d1\nstruts.i18n.reload=true\n#\u6587\u4ef6\u4e0a\u4f20\u6700\u5927\u503c\nstruts.multipart.maxSize=102400\n#\u8bbe\u7f6e\u4e0a\u4f20\u6587\u4ef6\u4e34\u65f6\u76ee\u5f55\nstruts.multipart.saveDir=d:\/temp\n#\u8ba9 struts2 \u652f\u6301\u52a8\u6001\u65b9\u6cd5\u8c03\u7528\nstruts.enable.DynamicMethodInvocation=true\n#\u5141\u8bb8\u6807\u7b7e\u4e2d\u4f7f\u7528\u8868\u8fbe\u5f0f\u8bed\u6cd5\nstruts.tag.altSyntax=true<\/code><\/pre>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">2. struts.xml \u6838\u5fc3\u7ed3\u6784<\/h3>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n&lt;!DOCTYPE struts PUBLIC \"-\/\/Apache Software Foundation\/\/DTD Struts Configuration 2.3\/\/EN\" \"http:\/\/struts.apache.org\/dtds\/struts-2.3.dtd\"&gt;\n&lt;struts&gt;\n    &lt;package name=\"packageName\" namespace=\"\/test\" extends=\"struts-default\"&gt;\n        &lt;action name=\"actionName\" class=\"com.ittx.struts.action.UserAction\" method=\"methodName\"&gt;\n            &lt;result&gt;\/sucess.jsp&lt;\/result&gt;\n            &lt;result name=\"ADD\"&gt;\/result.jsp&lt;\/result&gt;\n        &lt;\/action&gt;\n    &lt;\/package&gt;\n&lt;\/struts&gt;<\/code><\/pre>\n<table style=\"display: table; text-align: left; overflow: auto; border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; overflow-wrap: break-word; word-break: break-all;\" width=\"800\">\n<thead>\n<tr>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u6807\u7b7e<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u4f5c\u7528<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u5173\u952e\u5c5e\u6027<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">package<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u628a\u591a\u4e2a Action \u7ec4\u7ec7\u6210\u4e00\u4e2a\u6a21\u5757<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">name\u3001extends\u3001namespace\u3002namespace=\/test \u65f6\u8bbf\u95ee\u5730\u5740\u662f http:\/\/localhost:8080\/struts2\/test\/actionName.action<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">action<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u5b9a\u4e49\u8bbf\u95ee\u540d\u3001\u7c7b\u3001\u65b9\u6cd5\u53ca\u8fd4\u56de\u9875<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">name\u3001class\u3001method<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">result<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u6307\u5b9a\u54cd\u5e94\u7c7b\u578b\u548c\u54cd\u5e94\u9875\u9762<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">name \u5bf9\u5e94 Action \u8fd4\u56de\u503c\uff1btype \u4e0d\u5199\u5219\u7528\u7236 package \u9ed8\u8ba4 dispatcher<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"margin: 1em 0px;\">\u66f4\u5b8c\u6574\u7684 struts.xml \u793a\u4f8b\uff08include\u3001\u62e6\u622a\u5668\u6808\u3001\u5168\u5c40 result\u3001param\uff09\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n&lt;!DOCTYPE struts PUBLIC \"-\/\/Apache Software Foundation\/\/DTD Struts Configuration 2.0\/\/EN\" \"http:\/\/struts.apache.org\/dtds\/struts-2.0.dtd\"&gt;\n&lt;struts&gt;\n    &lt;!-- include \u662f\u7ec4\u4ef6\u5316\u65b9\u5f0f\uff1a\u6bcf\u4e2a\u529f\u80fd\u6a21\u5757\u72ec\u7acb xml\uff0c\u518d\u7528 include \u5f15\u7528 --&gt;\n    &lt;include file=\"struts-default.xml\"&gt;&lt;\/include&gt;\n\n    &lt;!--\n        package \u7684\u540d\u5b57\u5fc5\u987b\u552f\u4e00\uff1b\u53ef\u4ee5 extends \u7236 package\uff0c\u7236 package \u5fc5\u987b\u5199\u5728\u5b50 package \u524d\u9762\n        abstract=true \u65f6\u4e0d\u80fd\u5b9a\u4e49 action\n        namespace \u5f71\u54cd URL\uff0c\u4f8b\u5982 \/test \u5bf9\u5e94 http:\/\/localhost:8080\/struts2\/test\/XX.action\n    --&gt;\n    &lt;package name=\"com.kay.struts2\" extends=\"struts-default\" namespace=\"\/test\"&gt;\n        &lt;interceptors&gt;\n            &lt;interceptor name=\"timer\" class=\"com.kay.timer\"&gt;&lt;\/interceptor&gt;\n            &lt;interceptor name=\"logger\" class=\"com.kay.logger\"&gt;&lt;\/interceptor&gt;\n            &lt;interceptor-stack name=\"mystack\"&gt;\n                &lt;interceptor-ref name=\"timer\"&gt;&lt;\/interceptor-ref&gt;\n                &lt;interceptor-ref name=\"logger\"&gt;&lt;\/interceptor-ref&gt;\n            &lt;\/interceptor-stack&gt;\n        &lt;\/interceptors&gt;\n\n        &lt;!-- \u9ed8\u8ba4\u62e6\u622a\u5668\uff1a\u6bcf\u4e2a Action \u81ea\u52a8\u5f15\u7528\uff1bAction \u91cc\u82e5\u53e6\u5f15\u62e6\u622a\u5668\uff0c\u9ed8\u8ba4\u62e6\u622a\u5668\u5931\u6548 --&gt;\n        &lt;default-interceptor-ref name=\"mystack\"&gt;&lt;\/default-interceptor-ref&gt;\n\n        &lt;global-results&gt;\n            &lt;result name=\"input\"&gt;\/error.jsp&lt;\/result&gt;\n        &lt;\/global-results&gt;\n\n        &lt;!-- \u4e00\u4e2a Action \u53ef\u591a\u6b21\u6620\u5c04\uff0c\u53ea\u8981 name \u4e0d\u540c --&gt;\n        &lt;action name=\"hello\" class=\"com.kay.struts2.Action.LoginAction\"&gt;\n            &lt;interceptor-ref name=\"timer\"&gt;&lt;\/interceptor-ref&gt;\n            &lt;result name=\"success\" type=\"dispatcher\"&gt;\/talk.jsp&lt;\/result&gt;\n            &lt;!-- name \u5bf9\u5e94 Action \u4e2d\u7684 get\/set --&gt;\n            &lt;param name=\"url\"&gt;http:\/\/www.sina.com&lt;\/param&gt;\n        &lt;\/action&gt;\n    &lt;\/package&gt;\n&lt;\/struts&gt;<\/code><\/pre>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e8c\u3001Action \u641c\u7d22\u987a\u5e8f<\/h2>\n<p style=\"margin: 1em 0px;\">\u65b0\u5efa\u9879\u76ee\u547d\u540d\u4e3a struts2\uff0c\u6309\u4e0b\u9762\u914d\u7f6e\u4e00\u4e2a Action\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;package name=\"hello\" namespace=\"\/test\" extends=\"struts-default\"&gt;\n    &lt;action name=\"helloworld\" class=\"com.ittx.struts.action.HelloWorldAction\" method=\"execute\"&gt;\n        &lt;result name=\"success\"&gt;\/hello.jsp&lt;\/result&gt;\n    &lt;\/action&gt;\n&lt;\/package&gt;<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u90e8\u7f72\u540e\u8bbf\u95ee <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">http:\/\/localhost:8080\/struts2\/test\/sdf\/dsf\/32\/d\/helloworld.action<\/code> \u4f9d\u7136\u80fd\u6253\u5230\u8fd9\u4e2a Action\u3002Struts2 \u4f1a\u6309\u547d\u540d\u7a7a\u95f4<strong style=\"color: #4870ac;\">\u9010\u7ea7\u5f80\u4e0a\u622a<\/strong>\u6765\u641c\uff1a<\/p>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section>\u5148\u627e namespace \u4e3a \/test\/sdf\/dsf\/32\/d \u7684\u5305\u91cc\u6709\u6ca1\u6709 helloworld<\/section>\n<\/li>\n<li>\n<section>\u518d\u627e \/test\/sdf\/dsf\/32<\/section>\n<\/li>\n<li>\n<section>\u518d\u627e \/test\/sdf\/dsf<\/section>\n<\/li>\n<li>\n<section>\u518d\u627e \/test\/sdf<\/section>\n<\/li>\n<li>\n<section>\u518d\u627e \/test \u2014\u2014 \u8fd9\u91cc\u80fd\u641c\u5230\uff0c\u4e8e\u662f\u547d\u4e2d<\/section>\n<\/li>\n<\/ul>\n<p style=\"margin: 1em 0px;\">\u5982\u679c\u4e00\u8def\u622a\u5b8c\u90fd\u4e0d\u5b58\u5728\uff0c\u5c31\u4f1a\u5230 namespace \u4e3a <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">\"\"<\/code>\uff08\u9ed8\u8ba4\u547d\u540d\u7a7a\u95f4\uff09\u7684\u5305\u91cc\u7ee7\u7eed\u627e helloworld\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e09\u3001\u52a8\u6001\u65b9\u6cd5\u8c03\u7528<\/h2>\n<p style=\"margin: 1em 0px;\">\u4e00\u4e2a Action \u8981\u5bf9\u5e94\u591a\u4e2a\u8bf7\u6c42\u65f6\uff0c\u4e0d\u5fc5\u62c6\u6210\u4e00\u5806 Action \u7c7b\u3002\u52a8\u6001\u65b9\u6cd5\u8c03\u7528\u5e38\u89c1\u4e09\u79cd\uff1a<strong style=\"color: #4870ac;\">method \u5c5e\u6027<\/strong>\u3001<strong style=\"color: #4870ac;\">\u611f\u53f9\u53f7 !<\/strong>\u3001<strong style=\"color: #4870ac;\">\u901a\u914d\u7b26<\/strong>\u3002<\/p>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">\u7b2c\u4e00\u79cd\uff1aAction \u7684 method \u5c5e\u6027<\/h3>\n<p style=\"margin: 1em 0px;\">\u5728 Action \u91cc\u52a0 add()\u3001update()\uff0c\u518d\u5728 xml \u91cc\u7528 method \u6307\u8fc7\u53bb\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">public class UserAction extends ActionSupport {\n    public String add() {\n        log.debug(\"\u6267\u884cadd\u6dfb\u52a0\u7528\u6237\u64cd\u4f5c >>>>>>\");\n        return \"ADD\";\n    }\n\n    public String update() {\n        log.debug(\"\u6267\u884cupdate\u7528\u6237\u64cd\u4f5c >>>>>>\");\n        return \"UPDATE\";\n    }\n}<\/code><\/pre>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;action name=\"userAdd\" class=\"com.ittx.strutsproject.action.UserAction\" method=\"add\"&gt;\n    &lt;result name=\"ADD\"&gt;\/add_student.jsp&lt;\/result&gt;\n&lt;\/action&gt;\n&lt;action name=\"userUpdate\" class=\"com.ittx.strutsproject.action.UserAction\" method=\"update\"&gt;\n    &lt;result name=\"UPDATE\"&gt;\/update_student.jsp&lt;\/result&gt;\n&lt;\/action&gt;<\/code><\/pre>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section>\u6dfb\u52a0\uff1ahttp:\/\/localhost:8080\/struts2\/userAdd.action<\/section>\n<\/li>\n<li>\n<section>\u4fee\u6539\uff1ahttp:\/\/localhost:8080\/struts2\/userUpdate.action<\/section>\n<\/li>\n<\/ul>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">\u7b2c\u4e8c\u79cd\uff1a\u611f\u53f9\u53f7\u65b9\u5f0f !<\/h3>\n<p style=\"margin: 1em 0px;\">\u65b9\u6cd5\u4e0d\u591a\u65f6\uff0cmethod \u5c5e\u6027\u8fd8\u597d\u5199\u3002\u82e5\u6709\u4e0a\u767e\u4e2a\u65b9\u6cd5\uff0cxml \u4f1a\u81a8\u80c0\u3002\u8fd9\u65f6\u53ef\u4ee5\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">actionName!methodName<\/code>\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;action name=\"user\" class=\"com.ittx.strutsproject.action.UserAction\"&gt;\n    &lt;result&gt;\/sucess.jsp&lt;\/result&gt;\n    &lt;result name=\"ADD\"&gt;\/add_student.jsp&lt;\/result&gt;\n    &lt;result name=\"UPDATE\"&gt;\/update_student.jsp&lt;\/result&gt;\n&lt;\/action&gt;<\/code><\/pre>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section>\u6dfb\u52a0\uff1ahttp:\/\/localhost:8080\/struts2\/user!add.action<\/section>\n<\/li>\n<li>\n<section>\u4fee\u6539\uff1ahttp:\/\/localhost:8080\/struts2\/user!update.action<\/section>\n<\/li>\n<\/ul>\n<p style=\"margin: 1em 0px;\">\u5fc5\u987b\u5f00\u542f\u52a8\u6001\u65b9\u6cd5\u8c03\u7528\u3002Struts 2.5 \u8fd8\u8981\u5728 package \u4e0b\u653e\u5f00\u65b9\u6cd5\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;constant name=\"struts.enable.DynamicMethodInvocation\" value=\"true\"&gt;&lt;\/constant&gt;\n&lt;!-- Struts 2.5 \u611f\u53f9\u53f7 \/ \u901a\u914d\u7b26\u65e0\u6548\u65f6\uff0c\u5728 package \u4e0b\u52a0\uff1a --&gt;\n&lt;global-allowed-methods&gt;regex:.*&lt;\/global-allowed-methods&gt;<\/code><\/pre>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">\u7b2c\u4e09\u79cd\uff1a\u901a\u914d\u7b26\u65b9\u5f0f<\/h3>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;package name=\"student\" namespace=\"\/student\" extends=\"struts-default\"&gt;\n    &lt;!-- \u89e3\u51b3 struts2.5 \u901a\u914d\u7b26\u8c03\u7528\u65e0\u6548 --&gt;\n    &lt;global-allowed-methods&gt;regex:.*&lt;\/global-allowed-methods&gt;\n    &lt;action name=\"user_*\" class=\"com.ittx.strutsproject.action.UserAction\" method=\"{1}\"&gt;\n        &lt;result&gt;\/sucess.jsp&lt;\/result&gt;\n        &lt;result name=\"ADD\"&gt;\/add_student.jsp&lt;\/result&gt;\n        &lt;result name=\"UPDATE\"&gt;\/update_student.jsp&lt;\/result&gt;\n    &lt;\/action&gt;\n&lt;\/package&gt;<\/code><\/pre>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section>\u6dfb\u52a0\uff1ahttp:\/\/localhost:8080\/struts2\/user_add.action<\/section>\n<\/li>\n<li>\n<section>\u4fee\u6539\uff1ahttp:\/\/localhost:8080\/struts2\/user_update.action<\/section>\n<\/li>\n<\/ul>\n<p style=\"margin: 1em 0px;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">user_*<\/code> \u91cc\u7684 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">{1}<\/code> \u4f1a\u66ff\u6362\u6210\u7b2c\u4e00\u6bb5\u901a\u914d\u5185\u5bb9\uff0c\u4e8e\u662f <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">user_add<\/code> \u8c03 add()\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u56db\u3001struts2 \u63a5\u6536\u53c2\u6570\u7684\u51e0\u79cd\u5f62\u5f0f<\/h2>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">1. \u7528 Action \u7684\u5c5e\u6027<\/h3>\n<p style=\"margin: 1em 0px;\">\u5728 Action \u91cc\u5b9a\u4e49\u8981\u63a5\u6536\u7684\u5b57\u6bb5\uff0c\u63d0\u4f9b setter \/ getter\uff0c\u540d\u79f0\u548c\u63d0\u4ea4\u53c2\u6570\u4e00\u81f4\uff0c\u4e0d\u7528\u81ea\u5df1\u505a\u7c7b\u578b\u8f6c\u6362\u3002GET\u3001POST \u90fd\u53ef\u4ee5\uff0c\u4f8b\u5982 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">testAction?name=admin<\/code>\u3002<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;form action=\".\/user_add.do\" method=\"post\"&gt;\n    \u59d3\u540d:&lt;input type=\"text\" name=\"username\"\/&gt;&lt;br&gt;\n    \u5bc6\u7801:&lt;input type=\"text\" name=\"password\"\/&gt;&lt;br&gt;\n    &lt;input type=\"submit\" value=\"\u63d0\u4ea4\"\/&gt;&lt;br&gt;\n&lt;\/form&gt;<\/code><\/pre>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">public class TestAction extends ActionSupport {\n    private String username;\n    private String password;\n\n    public String getUsername() { return username; }\n    public void setUsername(String username) { this.username = username; }\n    public String getPassword() { return password; }\n    public void setPassword(String password) { this.password = password; }\n}<\/code><\/pre>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">2. \u4f7f\u7528 DomainModel<\/h3>\n<p style=\"margin: 1em 0px;\">Action \u91cc\u4e0d\u5fc5\u5806\u5f88\u591a\u5c5e\u6027\uff0c\u6539\u4e3a\u6301\u6709\u4e00\u4e2a Model \u5bf9\u8c61\u3002\u8868\u5355\u5b57\u6bb5\u5199\u6210 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">\u5bf9\u8c61\u540d.\u5c5e\u6027\u540d<\/code>\u3002\u6ce8\u610f\uff1a<strong style=\"color: #4870ac;\">\u4e0d\u8981\u81ea\u5df1 new<\/strong>\uff0cStruts \u4f1a\u81ea\u52a8\u5b9e\u4f8b\u5316\u3002<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;form action=\".\/user_add.do\" method=\"post\"&gt;\n    \u59d3\u540d:&lt;input type=\"text\" name=\"user.username\"\/&gt;&lt;br&gt;\n    \u5bc6\u7801:&lt;input type=\"text\" name=\"user.password\"\/&gt;&lt;br&gt;\n    &lt;input type=\"submit\" value=\"\u63d0\u4ea4\"\/&gt;&lt;br&gt;\n&lt;\/form&gt;<\/code><\/pre>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">public class TestAction extends ActionSupport {\n    \/\/ \u9519\u8bef\u5199\u6cd5\uff1a\u4e0d\u80fd\u81ea\u5df1\u5b9e\u4f8b\u5316\uff0cstruts \u4f1a\u81ea\u52a8\u5b9e\u4f8b\u5316\n    \/\/ private Users users = new Users();\n    private Users users;\n    public Users getUsers() { return users; }\n    public void setUsers(Users users) { this.users = users; }\n}<\/code><\/pre>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">public class User {\n    private String username;\n    private String password;\n    public String getUsername() { return username; }\n    public void setUsername(String username) { this.username = username; }\n    public String getPassword() { return password; }\n    public void setPassword(String password) { this.password = password; }\n}<\/code><\/pre>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">3. \u4f7f\u7528 ModelDriven<\/h3>\n<p style=\"margin: 1em 0px;\">Action \u5b9e\u73b0 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">ModelDriven<\/code>\uff0c\u6846\u67b6\u8c03\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">getModel()<\/code> \u62ff\u5230\u5bf9\u8c61\u3002\u8868\u5355\u5b57\u6bb5\u540d\u76f4\u63a5\u5199\u5c5e\u6027\u540d\uff0c\u4e0d\u5fc5\u52a0\u5bf9\u8c61\u524d\u7f00\u3002\u8fd9\u91cc\u8981<strong style=\"color: #4870ac;\">\u624b\u52a8 new<\/strong> \u6a21\u578b\u3002<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;form action=\".\/user_add.do\" method=\"post\"&gt;\n    \u59d3\u540d:&lt;input type=\"text\" name=\"username\"\/&gt;&lt;br&gt;\n    \u5bc6\u7801:&lt;input type=\"text\" name=\"password\"\/&gt;&lt;br&gt;\n    &lt;input type=\"submit\" value=\"\u63d0\u4ea4\"\/&gt;&lt;br&gt;\n&lt;\/form&gt;<\/code><\/pre>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">public class sysAction extends ActionSupport implements ModelDriven&lt;User&gt; {\n    private User user = new User(); \/\/ \u624b\u52a8\u5b9e\u4f8b\u5316\n\n    public User getModel() {\n        return user; \/\/ \u8fd4\u56de\u5b9e\u4f8b\n    }\n}<\/code><\/pre>\n<blockquote style=\"display: block; font-size: 0.9em; border-left: 3px solid #4870ac; padding: 0.5em 1em; margin: 0px; background: #f6f8fa; color: #40464f;\">\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">\u4e00\u53e5\u8bdd\u603b\u7ed3\uff1astruts.xml \u628a URL \u6307\u5230 Action\uff1b\u52a8\u6001\u65b9\u6cd5\u4f18\u5148\u7528\u901a\u914d\u7b26 user_* + method=&#8221;{1}&#8221;\uff1b\u6536\u53c2\u6570\u4e09\u79cd\uff1aAction \u5c5e\u6027\u3001DomainModel\uff08\u522b\u81ea\u5df1 new\uff09\u3001ModelDriven\uff08\u8981\u81ea\u5df1 new\uff09\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u628a Struts2 \u7528\u719f\u7ec3\uff0c\u65e5\u5e38\u56f4\u7740\u4e24\u4efd\u6587\u4ef6\u8f6c\uff1astruts.properties \u7ba1\u5e38\u91cf\uff0cstruts.xm [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[87],"tags":[183,190],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1846"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1846"}],"version-history":[{"count":3,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1846\/revisions"}],"predecessor-version":[{"id":1859,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1846\/revisions\/1859"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1846"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1846"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1846"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}