sfinnie
sfinnie

Reputation: 9952

Tomcat: possible to parse URL parameters containing '&'?

I have a servlet running on tomcat 6 which should be called as follows:

http://<server>/Address/Details?summary="Acme & co"

However: when I iterate through the parameters in the servlet code:

//...
while (paramNames.hasMoreElements()) {
    paramName = (String) paramNames.nextElement();
    if (paramName.equals("summary")) {
        summary = request.getParameter(paramName).toString();
    }
}
//...

the value of summary is "Acme ".

I assume tomcat ignores the quotes - so it sees "& co" as a second parameter (albeit improperly formed: there's no =...).

So: is there any way to avoid this? I want the value of summary to be "Acme & co". I tried replacing '&' in the URL with &amp; but that doesn't work (presumably because it's decoded back to a straight '&' before the params are parsed out).

Thanks.

Upvotes: 2

Views: 2852

Answers (3)

Masudul
Masudul

Reputation: 21961

Use http://<server>/Address/Details?summary="Acme %26 co". Because in URL special http symbol(e.g. &,/, //) does not work as parameters.

Upvotes: 1

avrono
avrono

Reputation: 1680

Are you encoding and decoding the URL with URLEncode ? If so, can you check what the input and output of those are ? Seems like one of the special characters is not being properly encoded/decoded

Try %26 for the &

Upvotes: 1

Related Questions