Struts Chinese processing problems

Source: Internet
Author: User

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 "));

%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.