Using jsp we print this Hh̵开发者_如何学Go7;k
value in hidden field and then submit it. Then in servlet, we are getting it as parameter Hh'k
, instead we want this as Hh’k
.
Any suggestions?
The browser don't do that because there's no reason. It just URL-encodes the special characters conform the application/www-x-form-urlencoded
contract which is automatically URL-decoded by calling getParameter()
.
If you really need to XML-escape them, you'd need to do it yourself after obtaining the request parameter. The Apache Commons Lang StringEscapeUtils#escapeXml()
is helpful in this:
String foo = request.getParameter("foo");
String escapedFoo = StringEscapeUtils.escapeXml(foo);
// ...
However, why would you do that? Do you have problems with redisplaying them in the HTML? For that there's a much easier solution, just use UTF-8 everywhere. E.g. add the following in top of your JSP:
<%@page pageEncoding="UTF-8" %>
Etcetera.
精彩评论