决定采用Julian Reschke的建议并违反规范!至少我添加了以下评论:
/* Note: strictly speaking (per section 14.30 of RFC 2616), the Location header
* requires an *absolute URI*. However, in practice, many web
* applications send an *absolute path* instead. This is interoperable,
* that is, works in popular web browsers (according to
* http://en.wikipedia.org/wiki/HTTP_location).
*
* As the information required to set the Location header to an absolute URI
* is not generally available to a Servlet, we go with the flow and send
* an absolute path instead (in violation of RFC 2616).
*
* There is an issue filed with Hypertext Transfer Protocol Bis (httpbis)
* working group to resolve this problem here:
* http://trac.tools.ietf.org/wg/httpbis/trac/ticket/185
*/
response.setHeader("Location", url);
我不想自己发送绝对URI的原因是因为我在负载均衡器和其他 生产环境 基础设施背后遇到了问题 . 虽然在开发模式下“http:// localhost:8080 / foo”趋于正常工作:))
现在接受朱利安的答案......