Reputation: 9952
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 &
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
Reputation: 3794
Try your parameter like
summary="Acme & 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
Upvotes: 1
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
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