Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with ampersand(&) in passing values through URL

 
archana vishwanath
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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???
 
Rohit Ahuja
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
u make that value as String.
I mean.
String s = a&&&a;
and then pass in the url as http://url?value=s;
 
velmurugan veerappan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64838
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Mishra Anshu
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64838
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's not much to it. For the example value in the original post:

will produce:

which is URL-safe.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic