{"id":906,"date":"2010-10-01T12:34:35","date_gmt":"2010-10-01T12:34:35","guid":{"rendered":"http:\/\/enjoyasp.net\/?p=906"},"modified":"2010-10-01T12:34:35","modified_gmt":"2010-10-01T12:34:35","slug":"servlet-struts1-x-struts2-0-%e6%af%94%e8%be%83","status":"publish","type":"post","link":"https:\/\/enjoyasp.net\/index.php\/2010\/10\/01\/servlet-struts1-x-struts2-0-%e6%af%94%e8%be%83\/","title":{"rendered":"Servlet, Struts1.x, Struts2.0 \u6bd4\u8f83"},"content":{"rendered":"<p>\u76f8\u540c\u7684\u90e8\u5206\uff1a<br \/>\n\u5ba2\u6237\u7aef\u53d1\u9001jsp\u9875\u9762\u8bf7\u6c42\uff0cServlet\u63a5\u6536\uff0c\u8bfb\u53d6web.xml\u6587\u4ef6 \uff0c\u636e\u4f20\u6765\u7684\u8def\u5f84\u8f6c\u5230\u5bf9\u5e94\u7684Servlet\uff0c\u8fdb\u884c\u64cd\u4f5c\uff0c<br \/>\n\u4e0d\u540c\u5728\u4e8e\u64cd\u4f5c\u65f6\u65b9\u6cd5\u540d\u662f\u5426\u56fa\u5b9a\uff0c\u662f\u5426\u987bextends\u6846\u67b6\u63d0\u4f9b\u7684\u7c7b<br \/>\nservlet\u8981\u81ea\u5b9a\u4e49\u63a5\u6536\u53c2\u6570\uff0cgetParameter, \u624b\u52a8\u8bbe\u7f6e\u54cd\u5e94\u8fd4\u56de\uff0c<br \/>\nPrintWriter out = response.getWriter();<br \/>\n    out.print( &#8220;<\/p>\n<table>&#8230;<\/table>\n<p>&#8221; );<br \/>\n\u800cstruts\u63a5\u6536\u6570\u636e\u5df2\u7531\u6846\u67b6\u672c\u8eab\u5b8c\u6210\u63a5\u53d7\uff0c\u800c\u8f6c\u5230\u67d0\u4e00\u9875\u9762\u5219\u53ef\u6307\u5b9a\uff0c\u4e0d\u662f\u624b\u52a8\u518d\u521b\u5efa\u3002<\/p>\n<p>\u5728web.xml\u4e09\u79cd\u6846\u67b6\u7684\u914d\u7f6e\u6bd4\u8f83<\/p>\n<p>ps: <url-pattern>\u4efb\u610f\u6307\u5b9a\uff0c\u5982\u53ef\u4ee5\u90fd\u4e3a*.action<\/p>\n<p>1\uff0c Servlet<br \/>\n <servlet><br \/>\n<servlet-name>AutoServlet<\/servlet-name><br \/>\n<servlet-class><br \/>\n    com.servlet.AutoServlet<br \/>\n<\/servlet-class><br \/>\n<\/servlet><br \/>\n<servlet-mapping><br \/>\n<servlet-name>AutoServlet<\/servlet-name><br \/>\n<url-pattern>\/AutoServlet<\/url-pattern><br \/>\n<\/servlet-mapping><\/p>\n<p>AutoServlet extends HttpServlet,\u5b9e\u73b0\u5176get,post\u65b9\u6cd5<br \/>\n\u5f53jsp\u8def\u5f84\u4e3a\/AutoServlet\u65f6\u6267\u884cget\u65b9\u6cd5,<br \/>\n\u53ef\u770b\u51fa\uff1a\u6240\u6709\u7684\u64cd\u4f5c\u7c7b\u90fd\u8981\u5728web.xml\u4e2d\u914d\u7f6e\uff0c\u4e0d\u80fd\u96c6\u4e0a\u7ba1\u7406\u8fd9\u4e9bservlet,\u800cStruts\u5206\u522b\u63d0\u4f9b\u4e86struts-config.xml,struts.xml\u96c6\u4e2d\u7ba1\u7406\u64cd\u4f5c\u7c7b\u7684\u6587\u4ef6<\/p>\n<p>\u6267\u884c\u7684\u65b9\u6cd5\u56fa\u5b9a\uff0cget,set<\/p>\n<p>2\uff0cStruts1.x<br \/>\n<servlet><br \/>\n<servlet-name>action<\/servlet-name><br \/>\n<servlet-class>org.apache.struts.action.ActionServlet<\/servlet-class><br \/>\n<init-param>\n<param-name>config<\/param-name>\n<param-value>\/WEB-INF\/struts-config.xml<\/param-value>\n<\/init-param><br \/>\n<\/servlet><br \/>\n<servlet-mapping><br \/>\n<servlet-name>action<\/servlet-name><br \/>\n<url-pattern>*.do<\/url-pattern><br \/>\n<\/servlet-mapping><br \/>\n\u5f53\u9875\u9762\u4f20\u6765*.do\u65f6\u6267\u884caction,\u8fd9\u662fStruts\u7cfb\u7edf\u63d0\u4f9b\u7684Servlet,\u5b83\u4f1a\u8bfb\u53d6<init-param>\u4e2d\u6240\u914d\u7f6e\u7684<br \/>\n\/WEB-INF\/struts-config.xml\u6587\u4ef6\uff0c\u8fdb\u4e00\u6b65\u627e\u5230\u5177\u4f53\u7684action\u8fdb\u884c\u64cd\u4f5c\u3002<\/p>\n<p>action \u65b9\u6cd5\u540d\u4e3aexecute, \u82e5\u5176\u5b83\u4efb\u610f\uff0c\u4e0d\u8fc7\u5fc5\u987b\u7ee7\u627fStruts1.x\u63d0\u4f9b\u7684action\u7c7b<\/p>\n<p>3,Struts2.0<br \/>\n<filter><br \/>\n<filter-name>struts2<\/filter-name><br \/>\n<filter-class><br \/>\n    org.apache.struts2.dispatcher.FilterDispatcher<br \/>\n<\/filter-class><br \/>\n<\/filter><br \/>\n<filter-mapping><br \/>\n<filter-name>struts2<\/filter-name><br \/>\n<url-pattern>*.action<\/url-pattern><br \/>\n<\/filter-mapping><br \/>\n\u5f53\u9875\u9762\u4f20\u6765*.action\u65f6\u6267\u884cFilterDispatcher,\u5b83\u4f1a\u8bfb\u53d6\/src\/struts.xml\u7684\u6587\u4ef6\uff0c\u4ece\u800c\u6267\u884c\u5bf9\u5e94\u7684\u7c7b<br \/>\naction\u65b9\u6cd5\u540d\u4efb\u610f\uff0c\u7c7b\u7ee7\u627f\u8c01\u6ca1\u6709\u9650\u5236\uff0c\u4e5f\u5c31\u662f\u8bf4\u4efb\u4f55\u7c7b\u90fd\u53ef\u4ee5\u6210\u4e3a\u4e00\u4e2aStruts1.x\u4e2d\u7684action<\/p>\n<p>\u6846\u67b6\u540d\u79f0          \u662f\u5426\u7ee7\u627f\u7279\u5b9a\u7c7b                         \u65b9\u6cd5\u540d                          \u96c6\u4e2d\u7ba1\u7406action\u7c7b\u6587\u4ef6<\/p>\n<p>servlet              \u662f\uff0cHttpServlet                         get, post                       \u65e0\uff0c \u4e00\u5207\u90fd\u5728web.xml\u4e2d\u914d\u7f6e<\/p>\n<p>struts1.x          \u662f\uff0cAction\uff0cDispatchAction       execute, \u4efb\u610f               \u6709\uff0cstruts-config.xml<\/p>\n<p>struts2.0           \u4efb\u610f                                         \u4efb\u610f                            \u6709\uff0cstruts.xml<\/p>\n<p>struts1.x  struts2.0 \u7ec6\u8282\u533a\u522b\uff1a<\/p>\n<p>\uff081\uff09\uff0c \u7c7b\u5f62\u5f0f\uff1astruts2.0\u7684action \u7c7b\u4f3c\u4e8estruts1.x\u4e2d\u7684DispatchAction \u4e0d\u8fc7\u524d\u8005\u7c7b\u968f\u610f\u7ee7\u627f\uff0c\u6ca1\u6709\u9650\u5236\uff0c\u800c\u540e\u8005\u5f3a\u5236\u8981\u7ee7\u627f\u81eaDispath\u624d\u53ef\u6267\u884c.<br \/>\n\uff082\uff09\uff0c   \u8fd0\u884c\uff1a   struts2.0\u7684action\u53ef\u76f4\u63a5\u5728 \u5730\u5740\u680f\u4e2d\u7528 http:\/\/pc-officea3:8080\/testWeb\/index.action.\u6267\u884c\u6d4b\u8bd5\uff0c\u800cstruts1.x\u5fc5\u987b\u8981\u6709jsp\u9875\u9762\u624d\u53ef<br \/>\n\uff083\uff09\uff0c   \u6d4b\u8bd5\uff1astruts1.xservlet API execute\u65b9\u6cd5I execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)\u66b4\u9732\u4e86servlet AP,\u5728\u6d4b\u8bd5\u65f6\u987b\u5728jsp\u9875\u9762\u4e2d\u63d0\u4ea4\uff0c\u751f\u6210request\u624d\u53ef\u8fdb\u884c\uff0c \u800cstruts2.0 \u65b9\u6cd5\u540d\u662f\u4efb\u610f\u7684\uff0c\u4e0d\u9650\u5236\u7684\u5982insert()\u65e0\u5f62\u53c2\uff0c\u53ef\u76f4\u63a5\u7528JUNITT\u7b49\u751f\u6210\u5bf9\u8c61\uff0c\u7528 myobject.set\u6765\u7ed9\u503c\uff0c\u6b64\u6b65\u76f8\u5f53\u4e8ejsp\u9875\u9762\u63d0\u4ea4\uff0c\u6700\u5927\u7684\u597d\u5904\u662f\u4e0d\u7528\u8f6c\u5230jsp\u9875\u9762\uff0c\u751f\u6210request\u624d\u80fd\u5f97\u5230\u6267\u884c\uff0c\u56e0struts2.0 action\u662f\u4efb\u610f\u7c7b\uff0c\u6545\u53ef\u5982\u4e00\u822c\u7c7b\u4e00\u6837\u8fdb\u884c\u6d4b\u8bd5\uff01\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76f8\u540c\u7684\u90e8\u5206\uff1a \u5ba2\u6237\u7aef\u53d1\u9001jsp\u9875\u9762\u8bf7\u6c42\uff0cServlet\u63a5\u6536\uff0c\u8bfb\u53d6web.xml\u6587\u4ef6 \uff0c\u636e\u4f20\u6765\u7684\u8def\u5f84\u8f6c\u5230\u5bf9\u5e94\u7684S [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"class_list":["post-906","post","type-post","status-publish","format-standard","hentry","category-struts2-0"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/906","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/comments?post=906"}],"version-history":[{"count":0,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/906\/revisions"}],"wp:attachment":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/media?parent=906"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/categories?post=906"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/tags?post=906"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}