java - 如何在 Spring Boot 中获取请求的 url
问题描述
我有以下控制器:
@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?
解决方案
您应该能够从 request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI) 中提取它
该线程有更多信息:web.xml 404 redirect to servlet, how to get the original URI?
推荐阅读
- c++ - 在 std::string::end() 和 std::string::capacity() 之间使用缓冲区
- swift - Type conversion error when reading data from Firebase
- python - Python how do it get pure data from user input in an entry widget=
- javascript - 如何将信息从 div 发送到电报机器人?
- django - 如何在 Django 中进行删除确认
- swiftui - 如何在 SwiftUI 中删除 HStack 上的 TextField 和 Text 之间的空格?
- openapi - what are mandatory elements in OpenAPI spec
- ruby-on-rails - 为什么belongs_to / has_many 和inverse_of 不能自动水合对方?
- python - Can anyone help me with reading a continuously updating video file with python?
- python - Running flask-socketio in thread