Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a & in the URL string

Status
Not open for further replies.

Einstein47

Programmer
Nov 29, 2001
737
US
I need to be able to pass the & character on the URL string. Is that possible?

My situation is rather complicated. I am maintaining a JSP/Servlet application that reads from the database and pulls various data elements for a specific record ID. The name is allowed to have special characters. The user selects the record id on a popup window which calls a servlet to get the info. It then takes the information and passes it to a special JSP page that parses the URL string for name/value pairs and does this:
Code:
window.opener.document.getElementById(&quot;<%=name%>&quot;).value=&quot;<%=value%>&quot;;
in a loop for all the name/value pairs it finds.

The big problem happens when a value has an & character because it is parsed as a pair separator goofs up all the rest of the pairs.

Can I simply escape the ampersand with a back-slash to keep it from being taken as a separator? Or do I need to do something more complicated? (my mind has started coming up with possible work-arounds, and none of them are pretty)

Any takers? Einstein47
(&quot;Vision without action is a daydream - Action without vision is a nightmare. Japanese Proverb&quot;)
 
don't know your particular situation, but i do have this to offer...

in a url if you have a '&' that must be passed, you use a key value query...

instead of:


use:


on the server side, you just convert the %26 or whatever to the proper character.

see this link for more info...


does that help?

- g
 
A co-worker set me straight. Since I am using JSP I just needed to call the java.net.URLEncoder.encode() method. It changes everything to %NN except for a-z, A-Z, 0-9, and certain other characters.

So, spewn, your information is correct. I'm just happy that I didn't need to create a method to do the translation for me. There are tons of nice Java utilities out there, the trouble is knowing where to look. Einstein47
(&quot;Vision without action is a daydream - Action without vision is a nightmare. Japanese Proverb&quot;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top