【问题标题】:How to get requested url in Spring boot [duplicate]如何在 Spring Boot 中获取请求的 url [重复]
【发布时间】:2018-07-26 21:11:36
【问题描述】:

我有以下控制器:

@Controller
public class MyErrorController implements ErrorController {

    @RequestMapping("/error")
    public String handleError(HttpServletRequest request, Model model) {

        Object url = request.getRequestURL()
        model.addAttribute("url", url)
        return "404";
    }

}

但是,即使用户访问了页面“http://mywebsite.com/does-not-exist”,上面的 url 总是给我 url“/error”。在生成错误页面之前如何检索用户输入的 url?

【问题讨论】:

    标签: java spring


    【解决方案1】:

    您应该可以从 request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI) 中提取它

    此线程有更多信息:web.xml 404 redirect to servlet, how to get the original URI?

    【讨论】:

      猜你喜欢
      • 2019-03-21
      • 1970-01-01
      • 2015-01-14
      • 2018-09-24
      • 2020-05-23
      • 2011-02-21
      • 1970-01-01
      • 2023-03-23
      • 2020-12-09
      相关资源
      最近更新 更多