| Author |
Encoding URL parameters
|
Justin Chu
Ranch Hand
Joined: Apr 19, 2002
Posts: 209
|
|
I'm passing some encoded string as a request parameter. I suppose the right way to do this in a JSP file is <input type="hidden" name="userId" value="<%=URLEncoder.encode("ENCRYPTED STRING HERE")%>"> Should I always use URLDecoder to decode the message?
|
 |
Bosun Bello
Ranch Hand
Joined: Nov 06, 2000
Posts: 1506
|
|
|
Just using request.getParameter automatically decodes it. I am not sure why you are even calling the URLEncoder method on it though.
|
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
|
 |
Frank Carver
Sheriff
Joined: Jan 07, 1999
Posts: 6913
|
|
Just to make it clear, URLEncoder does not encrypt a value, merely make sure that it contains no troublesome characters for a URL: ' ' is replaced by '+', other non-alphanumeric characters are replaced by a hexadecimal character code in the form "%AB". You only need to use URLEncoder if you are constructing a URL from scratch as a string, and it is quite rare to need to use URLDecoder as that is doen for you by the Servlet API.
|
A Convergent Visionary ~ Frank's Punchbarrel Blog ~ LinkedIn profile
|
 |
Justin Chu
Ranch Hand
Joined: Apr 19, 2002
Posts: 209
|
|
Yes. I'm manually concating an url link to be printed on a jsp page. Some browser versions will cause the link to be linked wrongly if the request parameters are not encoded. Chu
|
 |
Turlapati Hyma
Greenhorn
Joined: Jul 23, 2002
Posts: 2
|
|
Originally posted by Chu Tan: I'm passing some encoded string as a request parameter. hjdsfsdfsdfsdfsdfmessage?
(edited by Cindy) Turlapati, Why don't you experiment with UBB in "Meaningless Drivel" or "Blatant Advertising" and not clutter up the high traffic forums. Cindy [ July 23, 2002: Message edited by: Cindy Glass ]
|
 |
 |
|
|
subject: Encoding URL parameters
|
|
|