Java study notes 7-Spring mvc unified Exception Handling and static file configuration

Source: Internet
Author: User

1. it is convenient to implement unified Exception Handling in spring mvc, as long as. the page to be displayed when an exception is configured in xml, as shown in [html] <error-page> <exception-type> java. lang. exception </exception-type> <location>/html/500.htm</location> </error-page> <error-code> 404 </error-code> <location>/html/404.htm</location> </error-page> specifies the page displayed when an exception occurs as/html/500.htm. the page displays friendly prompts for users., avoid exposing error information. 2. What is the address of this/html/500.htm page in the project? If you follow the default configuration, the system will find the action of RequestMapping (value = "/html/500"). However, this page is a static page and does not need to go through mvc, therefore, you can configure the html directory to a static file directory to bypass mvc parsing. The configuration is as follows: [java] <beans: beans ........ <resources mapping = "/html/**" location = "/resources/html/"/> ......... in the bean file, the/html/* file is directed to a directory and accessed as a resource. In the same way, favicon can be implemented. ico access in the root directory [java] <resources mapping = "/favicon. ico "location ="/resources/images/favicon. ico "/> in this way, the following directory structure is attached:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.