Custom 404 using Spring DispatcherServlet

后端 未结 1 1008
再見小時候
再見小時候 2020-12-02 13:43

I\'ve set up web.xml as below. I also have an annotation-based controller, which takes in any URL pattern and then goes to the corresponding jsp (I\'ve set that up in the -

相关标签:
1条回答
  • 2020-12-02 14:28

    One option is to map all your error pages through your dispatcher servlet.

    Create a new HTTP error controller:

    
    @Controller
    public class HTTPErrorController {
    
        @RequestMapping(value="/errors/404.html")
        public String handle404() {
            return "errorPageTemplate";
        }
    
        @RequestMapping(value="/errors/403.html")
        ...
    
    }

    Map the error pages in web.xml

    <error-page>
        <error-code>404</error-code>
        <location>/errors/404.html</location>
    </error-page>
    0 讨论(0)
提交回复
热议问题