Struts Internationalization

xiaoxiao2021-03-06  83

Thoughts on the International Treatment of Struts - -

First, Struts Internationalization Struts is a web framework supporting international MVC. But how to use Struts internationalization is a problem. Let's discuss how to implement the internationalization of Struts. The internationalization of the Web program involves 3 levels. First, the input / output of the JSP section; the second, the application handler is international; third, DB internationalization. It is mainly discussed here that the input / output problem of the JSP portion is discussed. Second, the internationalization of the static part of the Struts JSP page static content (including static text, still pictures) internationalization, is achieved by resource files. To achieve internationalization, you need to do the following work: 1. Define the parameters of the moving ActionServlet of Web.xml; 2. Define resource files; 3. Define the character set of the JSP page; 4. Get the content in the resource file in the JSP page . 1. Define the parameters of the actionServlet for Web.xml action org.apache.struts.Action.ActionServlet config /web-inf/struts-config.xml Application ApplicationResources 2 2, define the resource file Add a UTF-8 resource bundle file below / web-inf / classes. Each resource file is a collection of "key-value" pairs. In the JSP page, you can find the corresponding data value by the key. This example of the file name is ApplicationResources, so the corresponding resource file is (including E-text, Simplified Chinese, Traditional Chinese) ApplicationResources.properties: Default resource file. When you can't find a resource in other resource files, the definition in this resource file is used. ApplicationResources_zh_cn.properties: Simplified Chinese resource file. ApplicationResources_zh_tw.properties: Traditional Chinese Resource File. The format of the resource file is: default resource file name _ country _ language .properties. Each file is converted through% java_hone% / bin / native2ascii.exe tool. You can also use other tools to process get (http://java.sun.com/products/jilkit/ There is a tool INTERNATIONALIZATION JAVA Internationalization and localization toolkit can handle). Below is an example, we show how to use the% java_hone% / bin / native2ascii.exe command to define the resource bundle file. 2.1 Preparing the file //applicationResources.properties; the default resource file, usually in English.

Label.username = username: label.password = password: //applicationresources_zh_cn.bak; Simplified Chinese resource file. The content inside is Chinese. It requires the tool to process the content into UTF-8Label.userName = username: label.password = password: //applicationResources_zh_tw.bak: Traditional Chinese resource file. The content inside is Chinese. It requires the tool to process the content into UTF-8, the following content is a traditional code. label.username = Techno Circular W:? label.password = Techno Circular W:? 2.2 preparation is completed, create a resource file UTF-8 bundle native2ascii -encoding gb2312 ApplicationResources_zh_CN.bak ApplicationResources_zh_CN.propertiesnative2ascii -encoding big5 Applica tionResources_zh_TW use the following command. Bak ApplicationResources_zh_tw.properties 3, Defining the Language of the JSP page to define the language of the JSP page to UTF-8. At each JSP page, you must have the following content (if you use template technology, you just need to add it on the template page, other pages that use this template do not need to be added) <% @ Page ContentType = Text / HTML; charset = UTF- 8 "%> 4, get the contents of the resource file in the JSP page. In the JSP, you need to display static contents in the Message label in the bean tag package of strus. For example, the following page

Ok, when this page is displayed, if the language collection of the customer is zh_cn, it will display the user. Name: Handle: If the language of the customer's IE is zh_tw, it will display the username: Username: You can choose to define the language of the IE in the IE tool -> Internet option-> language. Third, the processing of the data of the form. For the processing of form data, we are implemented by adding a filter. All submitted requests need to do character processing. Then define this filter in Web.xml. This way we don't need to do any character processing in the program. 3.1 Define the Filter. Below is an example.

转载请注明原文地址:https://www.9cbs.com/read-106666.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.041, SQL: 9