INFO: PageNotFound - No mapping found for HTTP request with URI [/appName/requestMapping/methodName] in DispatcherServlet with name 'dispatcher'
您好 我收到此错误,而请求的页面不可用,我的要求是如果请求的URL不可用,然后检查请求的URL与数据库并执行一些操作,所以我想抓住这个,如果有人可以帮助我,这将是很好的此,
谢谢
答案 0 :(得分:4)
要实现此目的,您可以在web.xml中定义<error-page>
条目,错误代码为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
...
}
答案 1 :(得分: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");
}