aspose file tools*
The moose likes Servlets and the fly likes Encoding URL parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Encoding URL parameters" Watch "Encoding URL parameters" New topic
Author

Encoding URL parameters

Justin Chu
Ranch Hand

Joined: Apr 19, 2002
Posts: 209
    
    1
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: 1510
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: 6920
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.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Justin Chu
Ranch Hand

Joined: Apr 19, 2002
Posts: 209
    
    1
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 ]
 
Consider Paul's rocket mass heater.
 
subject: Encoding URL parameters