Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

howto read a parameter from the URL (AS IS)

 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Consider the following URL:
http://localhost:8080/MyApplc/activate.do?value=H+43bVonNVFCDe2lRSzOID==

The idea is this: users receives this link (by email), they click the url and based on the 'value' the method does something.

problem: the value on the URL is H+43bVonNVFCDe2lRSzOID==



but the value of encrypted is H 43bVonNVFCDe2lRSzOID==
* the + sign after the H was removed"

So...how can I read the 'value' as is?

thank you!
 
Paul Clapham
Sheriff
Posts: 21126
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the parameter value was really supposed to be "H+43b..." and so on, then you should URL-encode that value before appending it to the URL. As it is, the servlet container is assuming that it was URL-encoded (as per the rules for URLs) and is URL-decoding it. This translates + to space, among other things.
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
almost...
the link was:

http://localhost:8080/MyApplc/activate.do?value=H+43bVonNVFCDe2lRSzOID==

the encrypted filed is H+43bVonNVFCDe2lRSzOID%3D%3D

'=' becomes 3D%

mmm....
 
Rob Spoor
Sheriff
Pie
Posts: 20546
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That value looks more like Base64 encoded, not URL encoded.
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that's correct, I have this line in my code that produces this:

cipherText = new BASE64Encoder().encode(byteCipherText);

how can I get around this?

thanks
 
Rob Spoor
Sheriff
Pie
Posts: 20546
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I would do:

When generating the URL, base64 it first, then URLencode. The + (part of the base64) will be replaced with %2B.
Then when you want to read it again, URLdecode it again (if the server doesn't do that for you), then de-base64 it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic