IntelliJ Java IDE
The moose likes HTML, CSS and JavaScript and the fly likes How to pass characters like+ as parameter in the URL Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "How to pass characters like+ as parameter in the URL " Watch "How to pass characters like+ as parameter in the URL " New topic
Author

How to pass characters like+ as parameter in the URL

Murali Koppula
Greenhorn

Joined: May 07, 2002
Posts: 10
I have a jsp file that accepts parameters from URL.
But when a character like + is part of the value of a parameter, its doesn't get passed (instead, it substitutes a space).
Is there an escape character to be used in such case? I tried using back slash (\), enclosing in quotes, using its value (043, #043, + etc.). Nothing seemed to work.
Any suggestions?
Thanks,
Murali.
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50677

If you are trying to encode the string on the client-side, the encodeURIComponent() function should do the trick for you.
On the server side, URLEncoder.encode() will perform the encoding.
Btw, '+' encodes as %2B.
hth,
bear


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2559

Shouldn't it be escape() on client side?
- Manish
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50677

escape() is deprecated.
bear
 
 
subject: How to pass characters like+ as parameter in the URL
 
Threads others viewed
Few Doubts about encoding
How to retrieve the parameters from a url in vaadin?
Sinhala Locale
How to implement login mechanism like JavaRanch has
how to pass parameter from dispatchto javascript
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com