FYI I'm using Tomcat v7.x.

I guess I misunderstood what happens when I use sendRedirect() - it sends a
new request, not a new response - but the effect is the same. That was what
I came away with when I read this:

http://javarevisited.blogspot.com/2011/09/sendredirect-forward-jsp-servlet.html

In any case, I gave up on using the header to pass additional items from
the server to the browser and ended up just using cookies. Unless someone
shows me otherwise, everything I saw online showed how to use
jQuery/xhr/your JS tool of the month to get header values from a GET/POST
response; meanwhile I never figured out how to extract those values after a
document was rendered in a traditional MVC app.

On Thu, Sep 8, 2016 at 11:22 AM Christopher Schultz <
ch...@christopherschultz.net> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> Joe,
>
> On 9/6/16 3:36 PM, Joe Tseng wrote:
> > I inherited a codebase that calls
> > HttpServletResponse.sendRedirect() to another page after a user is
> > successfully logged in. I want to be able to insert a header value
> > before that redirection is executed. I tried to simply add a
> > HttpServletResponse.addHeader()/.setHeader() to the response object
> > before the redirect is called, but it seems a new response object
> > is used and sent to the browser. Is that assessment correct? Is
> > there any way for me to modify the redirect before it's sent or do
> > I have to use .forward()?
>
> Tomcat version?
>
> This should work. Calling response.setHeader or response.addHeader and
> then response.sendRedirect() should include your custom headers. What
> makes you think that "a new response object is used"?
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
>
> iQIcBAEBCAAGBQJX0YIMAAoJEBzwKT+lPKRYq38QAKkGUiXnf0vDOvuedrjq8zry
> Nrc/mVhqezWJq0usCubNKeFPqMtHrGO8BJL4eUdVl/w6FVX0Srf/2C34APrgUJZC
> 9G0l4R8f8jatbnD2irqUo166Bq3TcjSjppdq3wYsGLb6vdRAkC9bMWqEr3piphBi
> yVdKTPflDXo5FEmHcxFgKctwCGzVaqXMJ4tyAEXHZ2jN6azK2mBwCtyZnakoo+Qy
> zFFbI6beczIAood49aohi6k0w/IGkH6KtbcYvWgbSuPoeRPrIUqZBb8VMZtrWF80
> oyyLa1+3gIGnxBv/4KCRUpLuz2iHdjJ/qwTBgiwNmpo68YZIoqN/ylm1VLR+A9Bx
> AV7+ifTZaBQ6oIRWFgziw6ZDtw5l3WCYX2LlyCrSGdbPA7IQ9fYSFNSX0iJUq668
> TUesB+5WapCmW73kZSB1OFYpxLTlJAMY3l8KvZbWfhQ3ozLLd8yKKVFBJ2HlM1i5
> GbquzKQ7qMWTVG89OUoK9b7Ipf1mApEg9CfvXnajcImM7QKASlUc0LEdtF5ujkEc
> mTSw4AYUs3M0jMOarMIE/sn1MMgsjJiDpQUWhxXcX0GjViI/AAyDGqMOuClGBOAw
> IaBhqC8fbgOV31BwA81C3bUcEKRFcYdMASViZO8G1B/bn+s70FFnf+JBqLI96XfI
> xhQuuThjTx2zCU7oLZb0
> =Izss
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>

Reply via email to