如何找出请求到达错误处理程序的url? [英] How to found out url with which the request arrived at error handler?

查看:27
本文介绍了如何找出请求到达错误处理程序的url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发送以下 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 - 导致错误分派的原始请求 uri
  • ERROR_SERVLET_NAME - 导致错误的 servlet 的名称
  • ERROR_STATUS_CODE - 为此错误调度确定的响应状态代码
  • ERROR_EXCEPTION - The exception object
  • ERROR_EXCEPTION_TYPE - The type of exception object
  • ERROR_MESSAGE - the exception message
  • ERROR_REQUEST_URI - the original request uri that caused the error dispatch
  • ERROR_SERVLET_NAME - the name of the servlet that caused the error
  • ERROR_STATUS_CODE - the response status code determined for this error dispatch

你想要的是

String originalUri = (String) request.getAttribute(
                                       RequestDispatcher.ERROR_REQUEST_URI)

这篇关于如何找出请求到达错误处理程序的url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆