This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Encoding URL parameters

 
Justin Chu
Ranch Hand
Posts: 209
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just using request.getParameter automatically decodes it. I am not sure why you are even calling the URLEncoder method on it though.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Justin Chu
Ranch Hand
Posts: 209
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic