The use of internationalization (i18n) i18n in struts can satisfy the internationalization of the system by placing all the flags on the page in a message resource file, different languages to provide different message resource files, and when the user logs on to the system, The system is based on the language you are logged in, select a different message resource file to display, so you can see the different effects. A, configuration file settings In fact, the use of i18n is relatively simple, First you configure the path to the message resource file in the Struts-config.xml configuration file, as follows:----------------------------------------------------------------------------- ---------------------<?xml version= "1.0" encoding= "iso-8859-1"? ><! DOCTYPE struts-config Public "-//apache Software foundation//dtd struts Configuration 1.1//en" "http:// Jakarta.apache.org/struts/dtds/struts-config_1_1.dtd "><struts-config> <!--======= = = = Form definitions ===================================--> <form-beans> <form-bean name= "Helloform" type= "Hello. Helloform "/>&Nbsp; </form-beans> <!--========== Global Forward definitions?==============================--> <global-forwards> <forward name= "Aerror" path= "/public/jsp/showerror.jsp"/> <forward name= "Success" path= "/public/jsp/showsuccess.jsp"/> </global-forwards> <!--========== Action Mapping definitions ==============================--> <action-mappings> <action path= "/helloworld " type=" hello. Helloaction " Name= "Helloform" scope= "Request" > <forward name= "SayHello" path= "/hello.jsp"/> </action> </action-mappings> <!--========== message definitions ===========================--> <!--Specify the path to the resource file--> <message-resources parameter= "Hello. Applicationresources "/>
</struts-config>---------------------------------------------------------------------------------------- ---configuration item <message-resources> of this profile is used to configure the resource file path, where the path is configured in the system Classpath hello/ Applicationresources.properties file. Second, the resource file now we can start to configure the resource file, as follows (applicationresources.properties file):----------------------------------------------------------------------------------- --------; Application Resources
Hello.title = Hello, welcome! -------------------------------------------------------------------------------------------in this configuration file, Only one comment (marked with commas), a message. For the Chinese language, the above document is no way to identify, you must give this file to convert the code to do. On the DOS command line, enter the folder where Applicationresources.properties resides: native2ascii-encoding gb2312 applicationresources.properties Applicationresources_zh.properties Native2ascii is a tool for JDK, placed in the bin directory of the JDK installation directory, if "NATIVE2ASCII is not internal command" appears, It may be that you have not set the environment variable.
Third, the JSP file below is a simple JSP file, which uses the i18n, as follows:---------------------------------------------------------------------------- ---------------<%@ page contenttype= "TEXT/HTML;CHARSET=GBK"%>
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.