Sometimes the cookie object returns incorrect value because the cookie contains value like "YWRtaW5pc3RyYXRvcg=="
but the cookie object getValue method returns like this "YWRtaW5pc3RyYXRvcg" without equal sign. Kindly provide solution for this
Well I think you are using Base 64 encoding here. I also used it in one of my projects to encode parameters but never used it with cookies. Try your program on a different servlet container. If you still get the same behavior than I think this is the default behavior and you'll have to use some different encoding...
Author and all-around good cowpoke
Joined: Mar 22, 2000
I suggest you trim any = signs out of the base64 string before setting the cookie.
Since they only exist to pad to a fixed length the absence should not cause a problem. See the wikipedia article i cited before.
Joined: Apr 25, 2003
That will not work in this scenario:
I have a service middleware, which passes this cookie, which is a siteminder authentication cookie, and if it does not contain the trailing "=", the authentication fails.
Joined: Feb 14, 2002
It might be notate the boundary [ CR / LF ] per base64 convention. Take a look at this ---> link and search for two equal sign (=) characters. You can also do some research on base64 boundary characters.
good luck, sen.
Joined: Sep 10, 2007
We were facing the same problem in our company. What we did to resolve this problem was to use the UrlEncoder to encode the cookie value before setting. This will encode all equals signs. And when retrieving the cookie we use UrlDecoder before using the value.
Both UrlEncoder and UrlDecoder can be found in the java.net package.