谁能告诉我为什么 servlet 中的重定向必须是绝对的?我找到的所有引用资料都告诉我它们必须是绝对的。
来自规范:
The
sendRedirect
method will set the appropriate headers and content body to redirect the client to a differentURL
. It is legal to call this method with a relativeURL
path, however the underlying container must translate the relative path to a fully qualifiedURL
for transmission back to the client. If a partialURL
is given and, for whatever reason, cannot be converted into a validURL
, then this method must throw anIllegalArgumentException
.
最佳答案
Section 14.30 of RFC 2616 (HTTP/1.1,自已取代)Location
header 中强制使用绝对 URL,用于指示重定向的“位置”。在最新版本的规范中,这一点已经放宽,但 Servlet 规范仍然需要向后兼容的行为。
关于java - 为什么 Servlet 中的重定向要求是绝对的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34219296/