dev*_*ull 5 java servlets http jetty
我想将相对重定向(到原始请求域和端口)发送到浏览器。
像这样:
Location: /app
Run Code Online (Sandbox Code Playgroud)
但Jetty自动发送完整的绝对路径
Location:http://10.0.2.17:9080/app
Run Code Online (Sandbox Code Playgroud)
文档还提到,servlet容器必须将相对 URL 转换为绝对 URL。
是否可以通过重定向发送相对 URL?
只需手动设置重定向状态和标头即可。替换response.sendRedirect(url)为
response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
response.setHeader("Location", url);
Run Code Online (Sandbox Code Playgroud)