如何找出请求到达错误处理程序的url? [英] How to found out url with which the request arrived at error handler?
问题描述
我发送以下 http 请求:
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";
}
在这种方法中,我想知道请求到达的 url.
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.
实际上,我没有在我的 spring mvc 应用程序中为 http://localhost:8081/member/createCompany/getSmallThumbnail/
映射控制器(url 已损坏).这个 url("/error") 在 web.xml 中配置为错误页面.
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.
推荐答案
您的请求已重新发送到 /error
(大概用于错误处理).
Your request got redispatched to /error
(presumably for error processing).
如果这个框架遵循正常的 Servlet 错误调度行为,那么您的原始请求可以在各种 javax.servlet.RequestDispatcher.ERROR_*
键.
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
- 异常对象ERROR_EXCEPTION_TYPE
- 异常对象的类型ERROR_MESSAGE
- 异常信息ERROR_REQUEST_URI
- 导致错误分派的原始请求 uriERROR_SERVLET_NAME
- 导致错误的 servlet 的名称ERROR_STATUS_CODE
- 为此错误调度确定的响应状态代码
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
你想要的是
String originalUri = (String) request.getAttribute(
RequestDispatcher.ERROR_REQUEST_URI)
这篇关于如何找出请求到达错误处理程序的url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!