Springmvc Specify 404, 500 error pages

Source: Internet
Author: User
Tags log4j

1. Append in Web. xml

    <Error-page>        <Error-code>404</Error-code>        < Location>/404</ Location>    </Error-page>    <Error-page>        <Error-code>500</Error-code>        < Location>/500</ Location>    </Error-page>

* Note Slash/

2. Append a Controller

 PackageIo.deolin.controller;Importjavax.servlet.http.HttpServletRequest;ImportOrg.apache.logging.log4j.LogManager;ImportOrg.apache.logging.log4j.Logger;ImportOrg.springframework.stereotype.Controller;Importorg.springframework.web.bind.annotation.RequestMapping; @Controller Public classErrorpagecontroller {Logger log= Logmanager.getlogger (Errorpagecontroller.class); @RequestMapping ("404")     PublicString page404 () {Log.info ("HTTP-400 Error"); return"HTTP-404"; } @RequestMapping ("500")     PublicString page500 () {Log.error (500); return"HTTP-500"; }}

* Note that the request URI remains consistent

You can test a URL that does not map to a request method and a static resource, such as

Http://localhost:8080/impossibleeeeeeeeeeeeeeeeeeeee

Then the browser's page content is the content of http-404.html.

Springmvc Specify 404, 500 error pages

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.