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
problem.
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...
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12268
1
posted
0
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.
Bill
Piyush Jain
Ranch Hand
Joined: Apr 25, 2003
Posts: 60
posted
0
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.
senthil doraiswamy
Greenhorn
Joined: Feb 14, 2002
Posts: 9
posted
0
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.
Kah Tang
Ranch Hand
Joined: Sep 10, 2007
Posts: 58
posted
0
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.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.