| Author |
problem with ampersand(&) in passing values through URL
|
archana vishwanath
Ranch Hand
Joined: Mar 09, 2004
Posts: 39
|
|
Hi! This is the problem I face some times when using get method to pass values from one page to other.If the values im trying to pass has some ampersands(&) (e.g) say <a href="http://localhost/file2.jsp?value=aa<b rel="nofollow">&&&&&</b>aaa" target="_blank">http://localhost/file2.jsp?value=aa&&&&&aaa purposely I have added some ampersands for value and im sure this will end up in problem Is there any way to overcome this???
|
 |
Deepak A
Ranch Hand
Joined: Oct 04, 2001
Posts: 120
|
|
u make that value as String. I mean. String s = a&&&a; and then pass in the url as http://url?value=s;
|
Face Off.
|
 |
velmurugan veerappan
Greenhorn
Joined: Apr 01, 2004
Posts: 3
|
|
hi, i think this is not possible. because every query string key-value pairse is parsed using &. thanks, velmurugan veerappan
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56200
|
|
Of course it is possible, and simply making it a string will do nothing for you. All your URL values should be URL-encoded. You can easily accomplish this with the help of the java.net.URLEncoder class. This will encode special characters (such as the &) to a form that will not confuse the format of the URL. [ April 01, 2004: Message edited by: Bear Bibeault ]
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Mishra Anshu
Ranch Hand
Joined: Sep 16, 2003
Posts: 224
|
|
Hello Bear, Can you provide an exapmle or some snippet of the code for using this encoder class. On Google...there are lots.... A basic snippet would solve the purpose
|
"Ignorance is bliss"
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56200
|
|
There's not much to it. For the example value in the original post: will produce: which is URL-safe.
|
 |
 |
|
|
subject: problem with ampersand(&) in passing values through URL
|
|
|