{"id":220,"date":"2020-08-08T22:46:53","date_gmt":"2020-08-08T14:46:53","guid":{"rendered":"http:\/\/moyisuiying.com\/?p=220"},"modified":"2020-12-10T14:24:25","modified_gmt":"2020-12-10T06:24:25","slug":"%e8%af%a6%e8%a7%a3%e8%87%aa%e5%ae%9a%e4%b9%89%e7%9a%84springmvc%e5%bc%82%e5%b8%b8%e4%bb%a5%e5%8f%8a%e5%ae%9e%e7%8e%b0%e6%b5%8b%e8%af%95","status":"publish","type":"post","link":"http:\/\/moyisuiying.com\/index.php\/javastudy\/springmvc\/220.html","title":{"rendered":"\u8be6\u89e3\u81ea\u5b9a\u4e49\u7684SpringMVC\u5f02\u5e38\u4ee5\u53ca\u5b9e\u73b0\u6d4b\u8bd5"},"content":{"rendered":"\n<p>\u6211\u4eec\u5728\u5199web\u9879\u76ee\u7684\u65f6\u5019\uff0c\u5982\u679c\u670d\u52a1\u5668\u4ee3\u7801\u51fa\u73b0\u9519\u8bef\uff0c\u90a3\u4e48\u5c31\u4f1a\u4ea7\u751f\u5f02\u5e38\uff0c\u5982\u679c\u6211\u4eec\u6ca1\u6709\u5bf9\u8fd9\u4e2a\u5f02\u5e38\u8fdb\u884c\u5904\u7406\uff0c\u90a3\u4e48\u8be5\u5f02\u5e38\u4f1a\u5728\u524d\u7aef\u9875\u9762\uff0c\u4e5f\u5c31\u662f\u6d4f\u89c8\u5668\u7684\u9875\u9762\u4e2d\u5c55\u793a\u51fa\u6765\uff0c\u5982\u4e0b\u56fe\uff1a<br><img   class=\"lazyload\" data-src=\"https:\/\/img-blog.csdnimg.cn\/20200808213654228.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><\/p >\n<noscript><img src=\"https:\/\/img-blog.csdnimg.cn\/20200808213654228.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><\/p><\/noscript>\n\n\n\n<p>\u8fd9\u6837\u5b50\u5bf9\u7528\u6237\u6765\u8bf4\u662f\u975e\u5e38\u4e0d\u53cb\u597d\u7684\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u81ea\u5b9a\u4e49\u7684\u5904\u7406\u5f02\u5e38\u7ec4\u4ef6\u6765\u8fdb\u884c\u5bf9\u8fd9\u4e2a\u5f02\u5e38\u5904\u7406\uff0c\u7136\u540e\u5c06\u53cb\u597d\u7684\u5904\u7406\u7ed3\u679c\u5728\u524d\u7aef\u9875\u9762\u4e2d\u5c55\u793a\u7ed9\u7528\u6237\u770b\u3002\u4e0b\u9762\u6211\u4eec\u5f00\u59cb\u81ea\u5b9a\u4e49\u5b9e\u73b0SpringMVC\u4e2d\u7684\u5f02\u5e38\u5904\u7406\u3002<br><strong>1.SpringMVC\u4e2d\u5f02\u5e38\u5904\u7406\u7684\u539f\u7406<\/strong><br>\u5728SpringMVC\u4e2d\uff0c\u5176\u9ed8\u8ba4\u7684\u5f02\u5e38\u5904\u7406\u662f\u9010\u7ea7\u5411\u4e0a\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u9762\u6211\u4eec\u5f00\u59cb\u4f7f\u7528\u4e09\u5f20\u56fe\u8fdb\u884c\u7406\u89e3\uff1a<br><img   class=\"lazyload\" data-src=\"https:\/\/img-blog.csdnimg.cn\/20200808221144610.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><\/p >\n<noscript><img src=\"https:\/\/img-blog.csdnimg.cn\/20200808221144610.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><\/p><\/noscript>\n\n\n\n<figure class=\"wp-block-image\"><img   class=\"lazyload\" data-src=\"https:\/\/img-blog.csdnimg.cn\/202008082210297.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"\/><\/figure >\n<noscript><img src=\"https:\/\/img-blog.csdnimg.cn\/202008082210297.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"\/><\/figure><\/noscript>\n\n\n\n<p><img  src=\"https:\/\/img-blog.csdnimg.cn\/20200808220937126.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br>\u6211\u4eec\u8981\u60f3\u5bf9\u8fd9\u4e9b\u5f02\u5e38\u8fdb\u884c\u5904\u7406\uff0cSpringMVC\u5728\u524d\u7aef\u63a7\u5236\u5668\u63d0\u4f9b\u4e86\u4e00\u4e9b\u5f02\u5e38\u5904\u7406\u7ec4\u4ef6\u4e13\u95e8\u8d1f\u8d23\u5904\u7406\u8fd9\u4e9b\u5f02\u5e38\uff0c\u6bd4\u5982\uff1a<br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200808221721907.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br>\u6211\u4eec\u8981\u60f3\u5b9e\u73b0\u81ea\u5b9a\u4e49\u7684\u5f02\u5e38\uff0c\u9700\u8981\u5b9e\u73b0HandlerExceptionResolver\u4e2d\u7684\u63a5\u53e3\uff0c\u7136\u540e\u518d\u5c06\u6211\u4eec\u81ea\u5b9a\u4e49\u7684\u5f02\u5e38\u89e3\u6790\u7c7b\u6ce8\u518c\u5230\u524d\u7aef\u63a7\u5236\u5668\u7684\u5f02\u5e38\u5904\u7406\u7ec4\u4ef6\u4e2d\u3002<br><strong>2.\u9879\u76ee\u7684\u642d\u5efa\u3002<\/strong><br>2.1\u65b0\u5efa\u4e00\u4e2amaven\u7684webapp\u9879\u76ee\u3002<br><img  class=\"lazyload\" data-src=\"https:\/\/img-blog.csdnimg.cn\/20200808222309822.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br>2.2\u5728pom.xml\u4e2d\u5f15\u5165\u4f9d\u8d56\u6587\u4ef6<\/p >\n<noscript><img src=\"https:\/\/img-blog.csdnimg.cn\/20200808220937126.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br>\u6211\u4eec\u8981\u60f3\u5bf9\u8fd9\u4e9b\u5f02\u5e38\u8fdb\u884c\u5904\u7406\uff0cSpringMVC\u5728\u524d\u7aef\u63a7\u5236\u5668\u63d0\u4f9b\u4e86\u4e00\u4e9b\u5f02\u5e38\u5904\u7406\u7ec4\u4ef6\u4e13\u95e8\u8d1f\u8d23\u5904\u7406\u8fd9\u4e9b\u5f02\u5e38\uff0c\u6bd4\u5982\uff1a<br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200808221721907.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br>\u6211\u4eec\u8981\u60f3\u5b9e\u73b0\u81ea\u5b9a\u4e49\u7684\u5f02\u5e38\uff0c\u9700\u8981\u5b9e\u73b0HandlerExceptionResolver\u4e2d\u7684\u63a5\u53e3\uff0c\u7136\u540e\u518d\u5c06\u6211\u4eec\u81ea\u5b9a\u4e49\u7684\u5f02\u5e38\u89e3\u6790\u7c7b\u6ce8\u518c\u5230\u524d\u7aef\u63a7\u5236\u5668\u7684\u5f02\u5e38\u5904\u7406\u7ec4\u4ef6\u4e2d\u3002<br><strong>2.\u9879\u76ee\u7684\u642d\u5efa\u3002<\/strong><br>2.1\u65b0\u5efa\u4e00\u4e2amaven\u7684webapp\u9879\u76ee\u3002<br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200808222309822.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br>2.2\u5728pom.xml\u4e2d\u5f15\u5165\u4f9d\u8d56\u6587\u4ef6<\/p><\/noscript>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n&lt;project xmlns=\"http:\/\/maven.apache.org\/POM\/4.0.0\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n  xsi:schemaLocation=\"http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd\">\n  &lt;modelVersion>4.0.0&lt;\/modelVersion>\n\n  &lt;groupId>org.example&lt;\/groupId>\n  &lt;artifactId>springmvc_exception&lt;\/artifactId>\n  &lt;version>1.0-SNAPSHOT&lt;\/version>\n  &lt;packaging>war&lt;\/packaging>\n\n  &lt;name>springmvc_exception Maven Webapp&lt;\/name>\n  &lt;!-- FIXME change it to the project's website -->\n  &lt;url>http:\/\/www.example.com&lt;\/url>\n\n  &lt;properties>\n    &lt;project.build.sourceEncoding>UTF-8&lt;\/project.build.sourceEncoding>\n    &lt;maven.compiler.source>1.8&lt;\/maven.compiler.source>\n    &lt;maven.compiler.target>1.8&lt;\/maven.compiler.target>\n    &lt;spring.version>5.2.8.RELEASE&lt;\/spring.version>\n  &lt;\/properties>\n\n  &lt;dependencies>\n    &lt;!-- https:\/\/mvnrepository.com\/artifact\/org.springframework\/spring-context -->\n    &lt;dependency>\n    &lt;groupId>org.springframework&lt;\/groupId>\n    &lt;artifactId>spring-context&lt;\/artifactId>\n    &lt;version>${spring.version}&lt;\/version>\n  &lt;\/dependency>\n    &lt;!-- https:\/\/mvnrepository.com\/artifact\/org.springframework\/spring-web -->\n    &lt;dependency>\n      &lt;groupId>org.springframework&lt;\/groupId>\n      &lt;artifactId>spring-web&lt;\/artifactId>\n      &lt;version>${spring.version}&lt;\/version>\n    &lt;\/dependency>\n    &lt;!-- https:\/\/mvnrepository.com\/artifact\/org.springframework\/spring-webmvc -->\n    &lt;dependency>\n      &lt;groupId>org.springframework&lt;\/groupId>\n      &lt;artifactId>spring-webmvc&lt;\/artifactId>\n      &lt;version>${spring.version}&lt;\/version>\n    &lt;\/dependency>\n    &lt;!-- https:\/\/mvnrepository.com\/artifact\/javax.servlet\/javax.servlet-api -->\n    &lt;dependency>\n      &lt;groupId>javax.servlet&lt;\/groupId>\n      &lt;artifactId>javax.servlet-api&lt;\/artifactId>\n      &lt;version>4.0.1&lt;\/version>\n      &lt;scope>provided&lt;\/scope>\n    &lt;\/dependency>\n    &lt;!-- https:\/\/mvnrepository.com\/artifact\/javax.servlet.jsp\/jsp-api -->\n    &lt;dependency>\n      &lt;groupId>javax.servlet.jsp&lt;\/groupId>\n      &lt;artifactId>jsp-api&lt;\/artifactId>\n      &lt;version>2.2.1-b03&lt;\/version>\n      &lt;scope>provided&lt;\/scope>\n    &lt;\/dependency>\n\n  &lt;\/dependencies>\n\n  &lt;build>\n    &lt;finalName>springmvc_exception&lt;\/finalName>\n    &lt;pluginManagement>&lt;!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->\n      &lt;plugins>\n        &lt;plugin>\n          &lt;artifactId>maven-clean-plugin&lt;\/artifactId>\n          &lt;version>3.1.0&lt;\/version>\n        &lt;\/plugin>\n        &lt;!-- see http:\/\/maven.apache.org\/ref\/current\/maven-core\/default-bindings.html#Plugin_bindings_for_war_packaging -->\n        &lt;plugin>\n          &lt;artifactId>maven-resources-plugin&lt;\/artifactId>\n          &lt;version>3.0.2&lt;\/version>\n        &lt;\/plugin>\n        &lt;plugin>\n          &lt;artifactId>maven-compiler-plugin&lt;\/artifactId>\n          &lt;version>3.8.0&lt;\/version>\n        &lt;\/plugin>\n        &lt;plugin>\n          &lt;artifactId>maven-surefire-plugin&lt;\/artifactId>\n          &lt;version>2.22.1&lt;\/version>\n        &lt;\/plugin>\n        &lt;plugin>\n          &lt;artifactId>maven-war-plugin&lt;\/artifactId>\n          &lt;version>3.2.2&lt;\/version>\n        &lt;\/plugin>\n        &lt;plugin>\n          &lt;artifactId>maven-install-plugin&lt;\/artifactId>\n          &lt;version>2.5.2&lt;\/version>\n        &lt;\/plugin>\n        &lt;plugin>\n          &lt;artifactId>maven-deploy-plugin&lt;\/artifactId>\n          &lt;version>2.8.2&lt;\/version>\n        &lt;\/plugin>\n      &lt;\/plugins>\n    &lt;\/pluginManagement>\n  &lt;\/build>\n&lt;\/project><\/code><\/pre>\n\n\n\n<p>2.3\u81ea\u5b9a\u4e49\u5f02\u5e38\u7c7b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package exception;\n\nimport org.springframework.web.servlet.HandlerExceptionResolver;\nimport org.springframework.web.servlet.ModelAndView;\n\nimport javax.servlet.http.HttpServletRequest;\nimport javax.servlet.http.HttpServletResponse;\n\n\/**\n * Classname:AccountExceptoin\n *\n * @description:\n * @author: \u964c\u610f\u968f\u5f71\n * @Date: 2020-08-08 17:06\n * @Version: 1.0\n **\/\npublic class AccountException extends Exception {\n    private String msg;\n\n    public AccountException(String msg) {\n        this.msg = msg;\n    }\n\n    public String getMsg() {\n        return msg;\n    }\n\n    public void setMsg(String msg) {\n        this.msg = msg;\n    }\n}<\/code><\/pre>\n\n\n\n<p>2.4\u81ea\u5b9a\u4e49\u5f02\u5e38\u89e3\u6790\u5668\uff0c\u5b9e\u73b0AccountExceptionResolver \u63a5\u53e3\u4e2d\u7684\u65b9\u6cd5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package exception;\n\nimport org.springframework.web.servlet.HandlerExceptionResolver;\nimport org.springframework.web.servlet.ModelAndView;\nimport javax.servlet.http.HttpServletRequest;\nimport javax.servlet.http.HttpServletResponse;\n\n\/**\n * Classname:AccountController\n *\n * @description:\n * @author: \u964c\u610f\u968f\u5f71\n * @Date: 2020-08-08 17:05\n * @Version: 1.0\n **\/\npublic class AccountExceptionResolver implements HandlerExceptionResolver {\n    @Override\n    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {\n        AccountException accountException = null;\n        if (e instanceof AccountException){\n         \/\/\u5f3a\u8f6c\u5f02\u5e38\n          accountException = (AccountException) e;\n        }else{\n            accountException = new AccountException(\"\u6b63\u5728\u51fa\u6545\u969c\u4e2d\u3002\u3002\u3002\u3002\u3002\u3002\");\n        }\n        ModelAndView modelAndView = new ModelAndView();\n        System.out.println(accountException.getMsg());\n        \/\/\u8bbe\u7f6e\u5f02\u5e38\u4fe1\u606f\n        modelAndView.addObject(\"msg\",accountException.getMsg());\n        \/\/\u8bbe\u7f6e\u5f02\u5e38\u8df3\u8f6c\u9875\u9762\n        modelAndView.setViewName(\"erro\");\n        return modelAndView;\n    }\n}<\/code><\/pre>\n\n\n\n<p>2.5\u4e66\u5199\u63a7\u5236\u5668\u4ee3\u7801<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package controller;\n\nimport exception.AccountException;\nimport org.springframework.stereotype.Controller;\nimport org.springframework.web.bind.annotation.RequestMapping;\n\n\/**\n * Classname:AccountController\n *\n * @description:\n * @author: \u964c\u610f\u968f\u5f71\n * @Date: 2020-08-08 18:18\n * @Version: 1.0\n **\/\n@Controller\n@RequestMapping(\"\/account\")\npublic class AccountController {\n    @RequestMapping(\"\/testException\")\n    public String testException() throws AccountException {\n        try {\n        \/\/\u6a21\u62df\u5f02\u5e38\n\/\/            int i=9\/0;\n        }catch (Exception e) {\n            e.printStackTrace();\n            throw new AccountException(\"\u6d4b\u8bd5\u5f02\u5e38\u9875\u9762\u51fa\u9519\u4e86\u3002\u3002\u3002\");\n        }\n\n        return  \"sucess\";\n    }\n}<\/code><\/pre>\n\n\n\n<p>2.6\u4e66\u5199\u524d\u7aef\u4ee3\u7801<br>2.6.1 \u9519\u8bef\u9875\u9762erro.jsp<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;%--\n  Created by IntelliJ IDEA.\n  User: \u964c\u610f\u968f\u5f71\n  Date: 2020\/8\/8 0008\n  Time: 17:27\n  To change this template use File | Settings | File Templates.\n--%>\n&lt;%@ page contentType=\"text\/html;charset=UTF-8\" language=\"java\" isELIgnored=\"false\" %>\n&lt;html>\n&lt;head>\n    &lt;title>\u9875\u9762\u8bbf\u95ee\u9519\u8bef&lt;\/title>\n&lt;\/head>\n&lt;body>\n&lt;h3>${msg}&lt;\/h3>\n&lt;\/body>\n&lt;\/html><\/code><\/pre>\n\n\n\n<p>2.6.2\u6210\u529f\u9875\u9762sucess.jsp<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;%--\n  Created by IntelliJ IDEA.\n  User: \u964c\u610f\u968f\u5f71\n  Date: 2020\/8\/8 0008\n  Time: 19:47\n  To change this template use File | Settings | File Templates.\n--%>\n&lt;%@ page contentType=\"text\/html;charset=UTF-8\" language=\"java\" %>\n&lt;html>\n&lt;head>\n    &lt;title>\u6210\u529f\u9875\u9762&lt;\/title>\n&lt;\/head>\n&lt;body>\n &lt;h2>\u8bbf\u95ee\u6210\u529f&lt;\/h2>\n&lt;\/body>\n&lt;\/html><\/code><\/pre>\n\n\n\n<p>3.6.3\u6d4b\u8bd5\u9875\u9762index.jsp<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;%--\n  Created by IntelliJ IDEA.\n  User: \u964c\u610f\u968f\u5f71\n  Date: 2020\/8\/8 0008\n  Time: 18:17\n  To change this template use File | Settings | File Templates.\n--%>\n&lt;%@ page contentType=\"text\/html;charset=UTF-8\" language=\"java\" isELIgnored=\"false\" %>\n&lt;html>\n&lt;head>\n    &lt;title>\u9996\u9875&lt;\/title>\n    &lt;script>\n        function btnClick() {\n         window.location.href=\"account\/testException\";\n        };\n    &lt;\/script>\n&lt;\/head>\n&lt;body>\n&lt;input type=\"button\" id=\"btn\" value=\"\u6d4b\u8bd5\u5f02\u5e38\" onclick=\" btnClick()\">\n&lt;\/body>\n&lt;\/html><\/code><\/pre>\n\n\n\n<p>3.\u914d\u7f6e\u6587\u4ef6<br>3.1\u5728springMvcConfig.xml\u7684\u914d\u7f6e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?>\n&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\n       xmlns:context=\"http:\/\/www.springframework.org\/schema\/context\"\n       xmlns:mvc=\"http:\/\/www.springframework.org\/schema\/mvc\"\n       xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n       xsi:schemaLocation=\"\n        http:&#47;&#47;www.springframework.org\/schema\/beans\n        http:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd\n        http:\/\/www.springframework.org\/schema\/context\n        http:\/\/www.springframework.org\/schema\/context\/spring-context.xsd\n        http:\/\/www.springframework.org\/schema\/mvc\n        http:\/\/www.springframework.org\/schema\/mvc\/spring-mvc.xsd\">\n&lt;!--  \u5f00\u542f\u6ce8\u89e3\u626b\u63cf\u5305-->\n    &lt;context:component-scan base-package=\"controller\">&lt;\/context:component-scan>\n&lt;!--    &lt;context:component-scan base-package=\"exception\">&lt;\/context:component-scan>-->\n&lt;!--    \u914d\u7f6e\u89c6\u56fe\u89e3\u6790\u5668-->\n    &lt;bean id=\"internalResourceViewResolver\" class=\"org.springframework.web.servlet.view.InternalResourceViewResolver\">\n        &lt;property name=\"prefix\" value=\"\/WEB-INF\/pages\/\">&lt;\/property>\n        &lt;property name=\"suffix\" value=\".jsp\">&lt;\/property>\n    &lt;\/bean>\n&lt;!--\u5f00\u542fMVC\u6ce8\u89e3\u652f\u6301-->\n    &lt;mvc:annotation-driven enable-matrix-variables=\"true\"\/>\n&lt;!--    \u914d\u7f6e\u81ea\u5b9a\u4e49\u5f02\u5e38\u89e3\u6790\u5668-->\n&lt;bean id=\"exceptionResolver\" class=\"exception.AccountExceptionResolver\">&lt;\/bean>\n&lt;\/beans><\/code><\/pre>\n\n\n\n<p>3.2\u914d\u7f6eweb.xml<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE web-app PUBLIC\n \"-\/\/Sun Microsystems, Inc.\/\/DTD Web Application 2.3\/\/EN\"\n \"http:\/\/java.sun.com\/dtd\/web-app_2_3.dtd\" >\n\n&lt;web-app>\n  &lt;display-name>Archetype Created Web Application&lt;\/display-name>\n&lt;!--  \u914d\u7f6e\u524d\u7aef\u63a7\u5236\u5668-->\n  &lt;servlet>\n    &lt;servlet-name>dispatcherServlet&lt;\/servlet-name>\n    &lt;servlet-class>org.springframework.web.servlet.DispatcherServlet&lt;\/servlet-class>\n&lt;!--    \u914d\u7f6e\u521d\u59cb\u5316\u53c2\u6570-->\n    &lt;init-param>\n      &lt;param-name>contextConfigLocation&lt;\/param-name>\n      &lt;param-value>classpath:springMvcConfig.xml&lt;\/param-value>\n    &lt;\/init-param>\n    &lt;load-on-startup>1&lt;\/load-on-startup>\n  &lt;\/servlet>\n  &lt;servlet-mapping>\n    &lt;servlet-name>dispatcherServlet&lt;\/servlet-name>\n    &lt;url-pattern>\/&lt;\/url-pattern>\n  &lt;\/servlet-mapping>\n&lt;!--  \u914d\u7f6e\u5b57\u7b26\u96c6\u7f16\u7801\u8fc7\u6ee4\u5668-->\n  &lt;filter>\n    &lt;filter-name>characterEncodingFilter&lt;\/filter-name>\n    &lt;filter-class>org.springframework.web.filter.CharacterEncodingFilter&lt;\/filter-class>\n    &lt;init-param>\n      &lt;param-name>encoding&lt;\/param-name>\n      &lt;param-value>UTF-8&lt;\/param-value>\n    &lt;\/init-param>\n\n  &lt;\/filter>\n  &lt;filter-mapping>\n    &lt;filter-name>characterEncodingFilter&lt;\/filter-name>\n    &lt;url-pattern>\/*&lt;\/url-pattern>\n  &lt;\/filter-mapping>\n&lt;\/web-app><\/code><\/pre>\n\n\n\n<p>4.\u5f00\u59cb\u6d4b\u8bd5<br>4.1\u6d4b\u8bd5\u6ca1\u6709\u5f02\u5e38\u65f6<br><img  src=\"https:\/\/img-blog.csdnimg.cn\/20200808223653292.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200808223715699.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br>4.2\u53bb\u6389\u6ce8\u91ca\uff0c\u6a21\u62df\u6d4b\u8bd5\u5f02\u5e38<br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200808223816939.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200808223825825.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200808223920555.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200808223934945.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br><img  class=\"lazyload\" data-src=\"https:\/\/img-blog.csdnimg.cn\/20200808223956694.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br>5.\u6b64\u6b21\u8fdb\u884c\u6d4b\u8bd5\u5f02\u5e38\u662f\u5728\u63a7\u5236\u5668controller\u5c42\u9762\u51fa\u73b0\u5f02\u5e38\uff0c\u5728\u5176\u5b83\u5730\u65b9\u5904\u7406\u5f02\u5e38\u4e5f\u662f\u4e00\u6837\u7684\u3002\u6b64\u6b21\u6d4b\u8bd5\u4ee3\u7801\u5df2\u7ecf\u4e0a\u4f20\u5230\u4e2a\u4eba\u535a\u5ba2\uff0c\u5982\u6709\u9700\u8981\u81ea\u884c\u4e0b\u8f7d\u89e3\u538b\u540e\u4ee5maven\u5de5\u7a0b\u5bfc\u5165\uff1a<a href=\"http:\/\/moyisuiying.com\/wp-content\/uploads\/2020\/08\/springmvc_exception.rar\">http:\/\/moyisuiying.com\/wp-content\/uploads\/2020\/08\/springmvc_exception.rar<\/a><\/p >\n<noscript><img src=\"https:\/\/img-blog.csdnimg.cn\/20200808223653292.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200808223715699.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br>4.2\u53bb\u6389\u6ce8\u91ca\uff0c\u6a21\u62df\u6d4b\u8bd5\u5f02\u5e38<br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200808223816939.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200808223825825.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200808223920555.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200808223934945.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200808223956694.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br>5.\u6b64\u6b21\u8fdb\u884c\u6d4b\u8bd5\u5f02\u5e38\u662f\u5728\u63a7\u5236\u5668controller\u5c42\u9762\u51fa\u73b0\u5f02\u5e38\uff0c\u5728\u5176\u5b83\u5730\u65b9\u5904\u7406\u5f02\u5e38\u4e5f\u662f\u4e00\u6837\u7684\u3002\u6b64\u6b21\u6d4b\u8bd5\u4ee3\u7801\u5df2\u7ecf\u4e0a\u4f20\u5230\u4e2a\u4eba\u535a\u5ba2\uff0c\u5982\u6709\u9700\u8981\u81ea\u884c\u4e0b\u8f7d\u89e3\u538b\u540e\u4ee5maven\u5de5\u7a0b\u5bfc\u5165\uff1a<a href=\"http:\/\/moyisuiying.com\/wp-content\/uploads\/2020\/08\/springmvc_exception.rar\">http:\/\/moyisuiying.com\/wp-content\/uploads\/2020\/08\/springmvc_exception.rar<\/a><\/p><\/noscript>\n","protected":false},"excerpt":{"rendered":"<p>\u81ea\u5b9a\u4e49\u5b9e\u73b0SpringMVC\u5f02\u5e38\u5e76\u8fdb\u884c\u6d4b\u8bd5<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[29],"tags":[33,34],"_links":{"self":[{"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/posts\/220"}],"collection":[{"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/comments?post=220"}],"version-history":[{"count":1,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/posts\/220\/revisions"}],"predecessor-version":[{"id":222,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/posts\/220\/revisions\/222"}],"wp:attachment":[{"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/media?parent=220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/categories?post=220"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/tags?post=220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}