comeOnGetIt comeOnGetIt - 7 months ago 11
HTML Question

& converted to & sometimes on request.getParameter("url") in jsp servlet

I have very simple input on HTML on JSP:

<input type="text" name="url" value="" />


User enters following value in above input:

http://www.example.com/param1=a&param2=b


On servlet side, when I do
request.getParameter("url")
I am getting following :

http://www.example.com/param1=a&amp;param2=b


How can I get original URL without
&amp;
from
request.getParameter
?

Answer

I finally found the solution. Just use org.apache.commons.lang.StringEscapeUtils.unescapeHtml(url) to escape any "&a m p;" (for that matter to escape any characters due to html encoding)