All Things Techie With Huge, Unstructured, Intuitive Leaps

Escape The Ampersand

I just spent several hours pulling out my hair trying to escape the ampersand character in an .aspx URL with parameters. The URL was a third party URL which needed to be encoded. I was working in JSP, JavaScript, XHTML, JSF, and JSTL.

It went something like this:

I constructed the string and tried to escape it with a "\". Of course, I quickly realized that it was illegal. There are only a few things that work with that escape character.

Then I tried the '& amp;' thing. That didn't work.

Then I tried the '% 26' thing. That didn't work.

I imported the URLEncoder and fed the string into that. It didn't work.

I tried using the URI constructor with the 5 input elements. I have more than 5 inputs and it kept throwing a path exception. Nothing seemed to work.

I tried most things and they didn't work.

What finally worked was the \u0026 thing.

In the JSP the URL looks like this:

String url = "\u0026Password=password\u0026accountNo=AcctNo";

Hope this helps somebody.

No comments:

Post a Comment