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

嗨 我得到這個錯誤,而所請求的頁面不速效,我的要求是,如果請求的URL是不可用,則檢查請求的URL與數據庫,並執行一些操作,所以我想抓住這一點,那將是巨大的,如果有人能幫助我在這,如何捕捉Spring MVC的映射沒找到,我使用Spring MVC的3.2.2

謝謝

回答

4

要做到這一點,你可以定義你的網絡的<error-page>進入.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 
    ... 
} 
+0

喜感謝回答,雅這個工作,但我不獲取URL,它返回null。 – user1918096

+0

嘗試此操作:\t \t request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);' –

+0

嘗試過但它返回空 – user1918096

0

最後我得到了這樣的請求的URL ..

@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"); 

}