{"id":1705,"date":"2017-07-28T14:39:56","date_gmt":"2017-07-28T06:39:56","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=1705"},"modified":"2017-07-28T14:39:56","modified_gmt":"2017-07-28T06:39:56","slug":"%e8%af%a6%e8%a7%a3servlet-filter%e4%b8%8espringmvc%e6%8b%a6%e6%88%aa%e5%99%a8%e7%9a%84%e5%8c%ba%e5%88%ab","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=1705","title":{"rendered":"\u8be6\u89e3Servlet filter\u4e0eSpringMVC\u62e6\u622a\u5668\u7684\u533a\u522b"},"content":{"rendered":"<p>\n\t\u5728struts2\u4e2d\u7528\u8fc7filter\u8fc7\u6ee4\u5668\uff0c\u5728springmvc\u4e2d\u8fd8\u6709\u62e6\u622a\u5668\uff0c\u5b83\u4eec\u90fd\u80fd\u8fc7\u6ee4\u8bf7\u6c42\uff0c\u4f46\u662f\u5230\u5e95\u6709\u4ec0\u4e48\u533a\u522b\u5462\uff1f&nbsp;\n<\/p>\n<h2>\n\t\u8fc7\u6ee4\u5668\u548c\u62e6\u622a\u5668\u7684\u533a\u522b<br \/>\n<\/h2>\n<ul>\n<li>\n\t\t\u62e6\u622a\u5668\u662f\u57fa\u4e8eJava\u7684\u53cd\u5c04\u673a\u5236\u7684\uff0c\u800c\u8fc7\u6ee4\u5668\u662f\u57fa\u4e8e\u51fd\u6570\u56de\u8c03\u3002\n\t<\/li>\n<li>\n\t\t\u62e6\u622a\u5668\u4e0d\u4f9d\u8d56\u4e0eservlet\u5bb9\u5668\uff0c\u8fc7\u6ee4\u5668\u4f9d\u8d56\u4e0eservlet\u5bb9\u5668\u3002\n\t<\/li>\n<li>\n\t\t\u62e6\u622a\u5668\u53ea\u80fd\u5bf9action\u8bf7\u6c42\u8d77\u4f5c\u7528\uff0c\u800c\u8fc7\u6ee4\u5668\u5219\u53ef\u4ee5\u5bf9\u51e0\u4e4e\u6240\u6709\u7684\u8bf7\u6c42\u8d77\u4f5c\u7528\u3002\n\t<\/li>\n<li>\n\t\t\u62e6\u622a\u5668\u53ef\u4ee5\u8bbf\u95eeaction\u4e0a\u4e0b\u6587\u3001\u503c\u6808\u91cc\u7684\u5bf9\u8c61\uff0c\u800c\u8fc7\u6ee4\u5668\u4e0d\u80fd\u8bbf\u95ee\u3002\n\t<\/li>\n<li>\n\t\t\u5728action\u7684\u751f\u547d\u5468\u671f\u4e2d\uff0c\u62e6\u622a\u5668\u53ef\u4ee5\u591a\u6b21\u88ab\u8c03\u7528\uff0c\u800c\u8fc7\u6ee4\u5668\u53ea\u80fd\u5728\u5bb9\u5668\u521d\u59cb\u5316\u65f6\u88ab\u8c03\u7528\u4e00\u6b21\u3002\n\t<\/li>\n<li>\n\t\t\u62e6\u622a\u5668\u53ef\u4ee5\u83b7\u53d6IOC\u5bb9\u5668\u4e2d\u7684\u5404\u4e2abean\uff0c\u800c\u8fc7\u6ee4\u5668\u5c31\u4e0d\u884c\uff0c\u8fd9\u70b9\u5f88\u91cd\u8981\uff0c\u5728\u62e6\u622a\u5668\u91cc\u6ce8\u5165\u4e00\u4e2aservice\uff0c\u53ef\u4ee5\u8c03\u7528\u4e1a\u52a1\u903b\u8f91\u3002\n\t<\/li>\n<\/ul>\n<p>\n\t<img decoding=\"async\" alt=\"SpringMVC\u8fc7\u6ee4\u5668\u548cServlet\u62e6\u622a\u5668\u7684\u533a\u522b\" src=\"http:\/\/img.blog.csdn.net\/20170728143648339\" style=\"width: 819px;height: 460px\" \/>\n<\/p>\n<h2>\n\t\u5b9a\u4e49\u4e0a\u7684\u533a\u522b<br \/>\n<\/h2>\n<ul>\n<li>\n\t\t\u62e6\u622a\u5668 \uff1a\u662f\u5728\u9762\u5411\u5207\u9762\u7f16\u7a0b\u7684\u5c31\u662f\u5728\u4f60\u7684service\u6216\u8005\u4e00\u4e2a\u65b9\u6cd5\uff0c\u524d\u8c03\u7528\u4e00\u4e2a\u65b9\u6cd5\uff0c\u6216\u8005\u5728\u65b9\u6cd5\u540e\u8c03\u7528\u4e00\u4e2a\u65b9\u6cd5\u6bd4\u5982\u52a8\u6001\u4ee3\u7406\u5c31\u662f\u62e6\u622a\u5668\u7684\u7b80\u5355\u5b9e\u73b0\uff0c\u5728\u4f60\u8c03\u7528\u65b9\u6cd5\u524d\u6253\u5370\u51fa\u5b57\u7b26\u4e32\uff08\u6216\u8005\u505a\u5176\u5b83\u4e1a\u52a1\u903b\u8f91\u7684\u64cd\u4f5c\uff09\uff0c\u4e5f\u53ef\u4ee5\u5728\u4f60\u8c03\u7528\u65b9\u6cd5\u540e\u6253\u5370\u51fa\u5b57\u7b26\u4e32\uff0c\u751a\u81f3\u5728\u4f60\u629b\u51fa\u5f02\u5e38\u7684\u65f6\u5019\u505a\u4e1a\u52a1\u903b\u8f91\u7684\u64cd\u4f5c\u3002\n\t<\/li>\n<li>\n\t\t\u8fc7\u6ee4\u5668\uff1a\u662f\u5728javaweb\u4e2d\uff0c\u4f60\u4f20\u5165\u7684request\u3001response\u63d0\u524d\u8fc7\u6ee4\u6389\u4e00\u4e9b\u4fe1\u606f\uff0c\u6216\u8005\u63d0\u524d\u8bbe\u7f6e\u4e00\u4e9b\u53c2\u6570\uff0c\u7136\u540e\u518d\u4f20\u5165servlet\u6216\u8005struts\u7684action\u8fdb\u884c\u4e1a\u52a1\u903b\u8f91\uff0c\u6bd4\u5982\u8fc7\u6ee4\u6389\u975e\u6cd5url\uff08\u4e0d\u662flogin.do\u7684\u5730\u5740\u8bf7\u6c42\uff0c\u5982\u679c\u7528\u6237\u6ca1\u6709\u767b\u9646\u90fd\u8fc7\u6ee4\u6389\uff09\uff0c\u6216\u8005\u5728\u4f20\u5165servlet\u6216\u8005 struts\u7684action\u524d\u7edf\u4e00\u8bbe\u7f6e\u5b57\u7b26\u96c6\uff0c\u6216\u8005\u53bb\u9664\u6389\u4e00\u4e9b\u975e\u6cd5\u5b57\u7b26\u3002\n\t<\/li>\n<\/ul>\n<h2>\n\txml\u6587\u4ef6\u914d\u7f6e\u7684\u533a\u522b<br \/>\n<\/h2>\n<p>\n\tfilter<br \/>\n\t\u8be5\u8fc7\u6ee4\u5668\u7684\u65b9\u6cd5\u662f\u521b\u5efa\u4e00\u4e2a\u7c7bXXXFilter\u5b9e\u73b0\u6b64\u63a5\u53e3\uff0c\u5e76\u5728\u8be5\u7c7b\u4e2d\u7684doFilter\u65b9\u6cd5\u4e2d\u58f0\u660e\u8fc7\u6ee4\u89c4\u5219\uff0c\u7136\u540e\u5728\u914d\u7f6e\u6587\u4ef6web.xml\u4e2d\u58f0\u660e\u4ed6\u6240\u8fc7\u6ee4\u7684\u8def\u5f84\u3002\n<\/p>\n<pre class=\"brush:xml;\">\r\n&lt;filter&gt;  \r\n  &lt;filter-name&gt;XXXFilter&lt;\/filter-name&gt;  \r\n  &lt;filter-class&gt;  \r\n     com.web.util.XXXFilter  \r\n  &lt;\/filter-class&gt;  \r\n&lt;\/filter&gt;\r\n&lt;filter-mapping&gt;  \r\n  &lt;filter-name&gt;XXXFilter&lt;\/filter-name&gt;  \r\n  &lt;url-pattern&gt;*.action&lt;\/url-pattern&gt;  \r\n&lt;\/filter-mapping&gt;  <\/pre>\n<p>\n\tInterceptor<br \/>\n\t\u5b83\u4e5f\u8981\u5b9e\u73b0HandlerInterceptor \u63a5\u53e3\uff0c\u8fd9\u91cc\u53ea\u4ecb\u7ecd\u65b9\u6cd5\u6ce8\u89e3\u914d\u7f6e\u3002\n<\/p>\n<pre class=\"brush:xml;\">\r\n&lt;!-- \u62e6\u622a\u5668 --&gt;\r\n&lt;mvc:interceptors&gt;\r\n    &lt;!-- \u591a\u4e2a\u62e6\u622a\u5668,\u987a\u5e8f\u6267\u884c --&gt;\r\n    &lt;mvc:interceptor&gt;\r\n       &lt;mvc:mapping path=&quot;\/entryOrJsonController\/*&quot; \/&gt;&lt;!-- \u5982\u679c\u4e0d\u914d\u7f6e\u6216\/*,\u5c06\u62e6\u622a\u6240\u6709\u7684Controller --&gt;   \r\n       &lt;bean class=&quot;com.wy.interceptor.CommonInterceptor&quot;&gt;&lt;\/bean&gt;  \r\n    &lt;\/mvc:interceptor&gt;\r\n&lt;\/mvc:interceptors&gt;<\/pre>\n<h2>\n\t\u5177\u4f53\u533a\u522b<br \/>\n<\/h2>\n<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" width=\"755\">\n<tbody>\n<tr>\n<td>\n\t\t\t\t&nbsp;\n\t\t\t<\/td>\n<td>\n\t\t\t\tfilter\n\t\t\t<\/td>\n<td>\n\t\t\t\tInterceptor\n\t\t\t<\/td>\n<\/tr>\n<tr>\n<td>\n\t\t\t\t\u591a\u4e2a\u7684\u6267\u884c\u987a\u5e8f\n\t\t\t<\/td>\n<td>\n\t\t\t\t\u6839\u636efilter&nbsp;mapping\u914d\u7f6e\u7684\u5148\u540e\u987a\u5e8f\n\t\t\t<\/td>\n<td>\n\t\t\t\t\u6309\u7167\u914d\u7f6e\u7684\u987a\u5e8f\uff0c\u4f46\u662f\u53ef\u4ee5\u901a\u8fc7order\u63a7\u5236\u987a\u5e8f\n\t\t\t<\/td>\n<\/tr>\n<tr>\n<td>\n\t\t\t\t\u89c4\u8303\n\t\t\t<\/td>\n<td>\n\t\t\t\t\u5728Servlet\u89c4\u8303\u4e2d\u5b9a\u4e49\u7684\uff0c\u662fServlet\u5bb9\u5668\u652f\u6301\u7684\n\t\t\t<\/td>\n<td>\n\t\t\t\tSpring\u5bb9\u5668\u5185\u7684\uff0c\u662fSpring\u6846\u67b6\u652f\u6301\u7684\u3002\n\t\t\t<\/td>\n<\/tr>\n<tr>\n<td>\n\t\t\t\t\u4f7f\u7528\u8303\u56f4\n\t\t\t<\/td>\n<td>\n\t\t\t\t\u53ea\u80fd\u7528\u4e8eWeb\u7a0b\u5e8f\u4e2d\n\t\t\t<\/td>\n<td>\n\t\t\t\t\u65e2\u53ef\u4ee5\u7528\u4e8eWeb\u7a0b\u5e8f\uff0c\u4e5f\u53ef\u4ee5\u7528\u4e8eApplication\u3001Swing\u7a0b\u5e8f\u4e2d\u3002\n\t\t\t<\/td>\n<\/tr>\n<tr>\n<td>\n\t\t\t\t\u6df1\u5ea6\n\t\t\t<\/td>\n<td>\n\t\t\t\tFilter\u5728\u53ea\u5728Servlet\u524d\u540e\u8d77\u4f5c\u7528\n\t\t\t<\/td>\n<td>\n\t\t\t\t\u62e6\u622a\u5668\u80fd\u591f\u6df1\u5165\u5230\u65b9\u6cd5\u524d\u540e\u3001\u5f02\u5e38\u629b\u51fa\u524d\u540e\u7b49\n\t\t\t<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\n\t\u603b\u7ed3<br \/>\n<\/h2>\n<p>\n\t\u4e24\u8005\u7684\u672c\u8d28\u533a\u522b\uff1a\u62e6\u622a\u5668\u662f\u57fa\u4e8eJava\u7684\u53cd\u5c04\u673a\u5236\u7684\uff0c\u800c\u8fc7\u6ee4\u5668\u662f\u57fa\u4e8e\u51fd\u6570\u56de\u8c03\u3002\u4ece\u7075\u6d3b\u6027\u4e0a\u8bf4\u62e6\u622a\u5668\u529f\u80fd\u66f4\u5f3a\u5927\u4e9b\uff0cFilter\u80fd\u505a\u7684\u4e8b\u60c5\uff0c\u4ed6\u90fd\u80fd\u505a\uff0c\u800c\u4e14\u53ef\u4ee5\u5728\u8bf7\u6c42\u524d\uff0c\u8bf7\u6c42\u540e\u6267\u884c\uff0c\u6bd4\u8f83\u7075\u6d3b\u3002Filter\u4e3b\u8981\u662f\u9488\u5bf9URL\u5730\u5740\u505a\u4e00\u4e2a\u7f16\u7801\u7684\u4e8b\u60c5\u3001\u8fc7\u6ee4\u6389\u6ca1\u7528\u7684\u53c2\u6570\u3001\u5b89\u5168\u6821\u9a8c\uff08\u6bd4\u8f83\u6cdb\u7684\uff0c\u6bd4\u5982\u767b\u5f55\u4e0d\u767b\u5f55\u4e4b\u7c7b\uff09\uff0c\u592a\u7ec6\u7684\u8bdd\uff0c\u8fd8\u662f\u5efa\u8bae\u7528interceptor\u3002\u4e0d\u8fc7\u8fd8\u662f\u6839\u636e\u4e0d\u540c\u60c5\u51b5\u9009\u62e9\u5408\u9002\u7684\u3002&nbsp;<\/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=1705\">\u8be6\u89e3Servlet filter\u4e0eSpringMVC\u62e6\u622a\u5668\u7684\u533a\u522b<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u5728struts2\u4e2d\u7528\u8fc7filter\u8fc7\u6ee4\u5668\uff0c\u5728springmvc\u4e2d\u8fd8\u6709\u62e6\u622a\u5668\uff0c\u5b83\u4eec\u90fd\u80fd\u8fc7\u6ee4\u8bf7\u6c42\uff0c\u4f46\u662f\u5230\u5e95\u6709\u4ec0\u4e48\u533a [&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":[1401,1359,413,1402],"class_list":["post-1705","post","type-post","status-publish","format-standard","hentry","category-java","tag-servlet","tag-spring-mvc-","tag-springmvc","tag-1402"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/1705","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=1705"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/1705\/revisions"}],"predecessor-version":[{"id":1706,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/1705\/revisions\/1706"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1705"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1705"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1705"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}