This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JSP and the fly likes problem with ampersand(&) in passing values through URL Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "problem with ampersand(&) in passing values through URL" Watch "problem with ampersand(&) in passing values through URL" New topic
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
    
  13

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
    
  13

There's not much to it. For the example value in the original post:

will produce:

which is URL-safe.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: problem with ampersand(&) in passing values through URL
 
Similar Threads
pass params from jsp to another jsp help
location bar of the browser on include/forward/sendRedirect
Repeat class method call 'new obj' question
Passing value from JSP to Cewolf Dataproducer Java File
Encoding ampersands in a URL