java重定向设置header,如何在Java中重定向请求时在HTTP标头中传递数据

is it possible to pass some data in HTTP Header, while redirecting a request from one server to another.

Here is my scenario,

I have one generic filter, via which every request is passing.

Now, based on some condition, I'm redirecting the request to some different server using the API objHttpServletResponse.sendRedirect(strURL).

But, the issue is, when I'm setting some data in response header like objHttpServletResponse.setHeader("Key", "Value"); That's not available in the redirected server.

So, my questions are,

1. Is there any way to pass some data in header while redirecting a request?

2. If not, what are the other possible ways to send some data while redirecting a request?

Please Note: few other ways, like

using URL parameters:

objHttpServletResponse.sendRedirect(strURL+"?param="+ strParamValue);

or

using session:

HttpSession session = httpRequest.getSession();

session.setAttribute("Key", "Value");

is not what I'm expecting.

解决方案

The headers you set are written to the response that gets sent to the client, along with a Location header and a status code. See Redirecting a request using servlets and the "setHeader" method not working

The client is then supposed to send an identical request to the URL you specified in the Location header. Identical to the request it sent to you.

You want the browser to send a header you specify along with the redirected request. Have you considered adding a (domain) Cookie header? Some googling leads me to believe that cookies set in a redirect response will get picked up by most browsers. See http://blog.dubbelboer.com/2012/11/25/302-cookie.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值