java+设置全局响应头,在Java Servlet应用程序中为HTTP 201响应设置Location标头的正确方法是什么...

决定采用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”趋于正常工作:))

现在接受朱利安的答案......

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值