开发者

Get ascii character set as ascii character set in servlet

开发者 https://www.devze.com 2023-04-06 03:31 出处:网络
Using jsp we print this Hh&#821开发者_如何学Go7;k value in hidden field and then submit it. Then in servlet, we are getting it as parameterHh\'k, instead we want this as Hh’k.

Using jsp we print this Hh&#821开发者_如何学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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号