About struts tag in character encoding problem

Category: Web Develop
 
huang20060315
2013-08-20 02:33:35

Sponsored Links
A test page: test.jsp

<% @ page contentType = "text / html"%>
<% @ page pageEncoding = "GBK"%>
<% @ taglib uri = "/ WEB-INF/struts-bean.tld" prefix = "bean"%> ;
<% @ taglib uri = "/ WEB-INF/struts-html.tld" prefix = "html"%>

<bean:define id="mycountry" value=" "/>
<p>
<html: link href = " ; "paramId =" country "paramName =" mycountry ">
link 1
</ html: link>
</p>

<p>
<html:link href="?mycountry= ">
Link 2
</ html: link>
</p>

compiled generated page "link 1" two Chinese characters garbled , and "Link 2" in the character, but the normal display. I look at the struts of the source code and found that the parameters are to undergo a UTF-8 encoded return after the last page in the jsp character encoding is generated url encoding:% E5% B4, etc., but I do not know how the browser not correctly identified, the first case generated garbled.

Note: All data exchanged by the filter struts for GBK encoding.

experts to help analyze please, thank you.

Sponsored Links

Rqxuyamei
2013-08-20 02:51:21
url of characters to use Encoder ~ recipient to use the Decoder ~
shouczt
2013-08-20 02:57:04
lz in Action Try the following methods:
1 , request.setCharacterEncoding ("GBK");
2, mycountry = java.net.URLEncoder.encode ("China"), ;
then use the Action java.net.URLDecoder.decode (...);
3, mycountry = new String ( mycountry.getBytes ("ISO-8859-1"), "GBK");
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.