1
INFO: PageNotFound - No mapping found for HTTP request with URI [/appName/requestMapping/methodName] in DispatcherServlet with name 'dispatcher'

嗨,当请求的页面不可用时,我收到此错误,我的要求是如果请求的 url 不可用,然后使用数据库检查请求的 URL 并执行一些操作,所以我想抓住这个,如果有人能帮助我,那就太好了在这,

谢谢

4

2 回答 2

4

为此,您可以<error-page>在 web.xml 中定义一个条目,其错误代码为404

<error-page>
    <error-code>404</error-code>
    <location>/404</location>
</error-page>

并定义一个处理程序方法来处理404映射:

@RequestMapping("404")
public String handlePageNotFound(HttpServletRequest request) {
    //this will return you the original URL for which this 404 happened     
    String originalUri = (String) request
            .getAttribute("javax.servlet.forward.request_uri");
    //here you can write your code to handle this 404 error
    ...
}
于 2013-10-11T12:14:38.657 回答
0

最后我得到了这样的请求网址..

@RequestMapping("404")
public String handlePageNotFound(HttpServletRequest request) {
    //this will return you the original URL for which this 404 happened     
   String originalUri = (String) request
                    .getAttribute("javax.servlet.error.request_uri");

}
于 2013-11-01T06:50:10.337 回答