2

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.

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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 &

1 Comment

+1 for the '%26' suggestion. Apparently you shouldn't use URLEncoder to encode URLs: stackoverflow.com/questions/4571346/….
1

Try your parameter like

summary="Acme &amp; co" 

& is part reserved characters. Refer RFC2396 section 2.2. Reserved Characters.

how to encode URL to avoid special characters in java

Characters allowed in GET parameter

HTTP URL - allowed characters in parameter names

http://illegalargumentexception.blogspot.in/2009/12/java-safe-character-handling-and-url.html

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.