问题
I send following http request:
http://localhost:8081/member/createCompany/getSmallThumbnail/
On server side I hit into controller method:
@RequestMapping("/error")
public String error(Model model, HttpServletRequest request){
if(request.getRequestURI().contains("thumbnail")){
System.out.println("thumbnail accepted");
}
request.toString();
model.addAttribute("message", "page not found");
return "errorPage";
}
At this method I want to know url with which the request arrived.
If in debug I stop inside this method I see information needed for me:
But I cannot find method in request which will return this.
Please help to return url which I want.
P.S.
Actually I have not mapped controller in my spring mvc application(url is broken) for http://localhost:8081/member/createCompany/getSmallThumbnail/
. This url("/error") configured in web.xml as error page.
回答1:
Your request got redispatched to /error
(presumably for error processing).
If this framework follows the normal Servlet error dispatching behavior, then your original request can be found in the HttpServletRequest.getAttributes()
under the various javax.servlet.RequestDispatcher.ERROR_* keys.
ERROR_EXCEPTION
- The exception objectERROR_EXCEPTION_TYPE
- The type of exception objectERROR_MESSAGE
- the exception messageERROR_REQUEST_URI
- the original request uri that caused the error dispatchERROR_SERVLET_NAME
- the name of the servlet that caused the errorERROR_STATUS_CODE
- the response status code determined for this error dispatch
What you want is
String originalUri = (String) request.getAttribute(
RequestDispatcher.ERROR_REQUEST_URI)
来源:https://stackoverflow.com/questions/32910492/how-to-found-out-url-with-which-the-request-arrived-at-error-handler