Struts Chinese processing problem jsp file
So the encoding is set to UTF-8
1) page command
<% @ Page contentType = "text/html; charset = UTF-8" %>
2) html header tag
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
Struts configuration file
Configure the resource style in the struts-config file
<Message-resources parameter = "MessageResources"/>
<Message-resources parameter = "ErrorMessages" key = "ErrorMessages"/>
<Message-resources parameter = "Test" key = "Test"/>
The default directory is under \ WEB-INF \ classes
If yes
<Message-resources parameter = "Error. Messages" key = "ErrorMessages"/>
The Messages. properties file under \ WEB-INF \ classes \ Error
Name of the corresponding international File
Default resource file ErrorMessages. properties
Chinese resource file ErrorMessages_zh_CN.properties
Generation of Chinese resource files:
1) create a temporary file ErrorMessages_xx.properties, And Enter Text Information in this file.
# -- Standard errors --
ErrorMessages. inputFriendPhone = Error 1
ErrorMessages. isNum = Error 2
Input. recommend. phone = * phone number of the recommender
Input. username = User Name:
2) run the following command: native2ascii-encoding GBK ErrorMessages_xx.properties.
ErrorMessages_zh_CN.properties
The generated file is as follows:
# -- Standard errors --
ErrorMessages. inputFriendPhone = \ u9519 \ u8bef1
ErrorMessages. isNum = \ u9519 \ u8bef2
Input. recommend. phone = * \ u63a8 \ u8350 \ u4eba \ u7684 \ u624b \ u673a \ u53f7 \ u7801
Input. username = \ u7528 \ u6237 \ u59d3 \ u540d:
3) Note that the Chinese name is xx_zh_CN.properties.
If the name is incorrect, the expected results will not be displayed.
Test
How to test in a common jsp file
Namespace used internationally in jsp files
<% @ Page import = "java. util. Locale" %>
<% @ Page import = "java. util. ResourceBundle" %>
<%
Locale locale = request. getLocale ();
System. out. println ("locale =" + locale. toString ());
Locale = new Locale ("zh", "CN ");
System. out. println ("locale =" + locale. toString ());
ResourceBundle messages = ResourceBundle. getBundle ("ErrorMessages", locale );
System. out. println (messages. getString ("input. recommend. phone "));
%>