I have made a Struts internationalized applet. In fact, I have more than half a year, but I feel that I have only seen the trees and don't see Lin, and I decided to make a good time to make a lessons today. Otherwise, I really want to become a worker in the pipeline. If there is any mistake, please have an ax. 1. Modify the web.xml file, the content is as follows: XML Version = "1.0" encoding = "UTF-8"?>
Firstly ApplicationResources_en.properties file, as follows: owner.greet = Greetowner.name = Nameowner.address = Addressowner.email = Emailowner.tel = Chinese source files corresponding to the content of Tel follows: owner.greet = call owner.name = Name of owner .address = address OWNER.EMAIL = Email Owner.tel = Contact Phone then execute native2ascii -encoding gbk applicationresources.source in the CMD. The Chinese source file generates the Chinese resource file, content as owner.greet = / u79f0 / u547cowner.name = / u59d3 / u540downer.address = / u5730 / u5740owner.email = / u7535 / u5b50 / u90ae / u4ef6owner.tel = / u8054 / u7cfb / u7535 / u8bdd introduce here, native2ascii It is a tool for the JDK package. If you can't CMD directly execute the native2ascii command, check your environment variable, not specifically introduced here.
3, then introduce the contents of the struts-config.xml file, if familiar with Struts, friends also feel very simple XML Version = "1.0" Encoding = "UTF-8"?> =================== -> Function ChangeLanguage (Language) {if (Language == "En") {document.all ("language"). Value = "en";} else {document.all ("language"). value = "cn";} Document.Forms [0] .Submit ();} script> head>
HTML: Cancel /> html: form>
html: html> Owneraction.java file content is as follows: // create by xslt generator for eclipse.// xsl: not found (java.io.filenotFoundException: (Bad file descriptor) // default xsl buy: easystruts.jar $ org.easystruts.xslgen.javaclass.xslpackage com.sharp.struts.Action;Import java.util.locale;
Import javax.servlet.http.httpservletRequest; import javax.servlet.http.httpservletResponse;
import org.apache.struts.Globals; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action .Action mapping; import org.apache.struts.Actions.dispatchaction;
Import com.sharp.struts.form.ownerformation;
/ ** * Owneraction.java created by Easystruts - xsltgen. * Http://easystruts.sf.net * created on 10-09-2004 * * xdoclet definition: * @struts: action path = "/ @Name =" ownerForm "input =" / owner.jsp "validate =" true "* @struts: action-forward name =" / success.jsp "path =" / success.jsp "* / public class OwnerAction extends DispatchAction {public ActionForward changeLanguage ( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {String language = request.getParameter ( "language"); if (language.equals ( "en").) {request.getSession () setAttribute (Globals.LOCALE_KEY, Locale .Ene {Request.getSession (). Setttribute (globals.locale_key, locale.chinese);} return mapping.findforward ("Owner");}} You need to pay attention to it, don't make a mistake, I am It took more than an hour, because the file name is wrong with Locale.English is a local object, and the getLanguage () method returns EN, the suffix of the resource file (ApplicationResources_en.properties) The same locale.Chinese is a Locale object, GetLanguage () Method Returns EN, with resource files (ApplicationResources_ZH _Cn.properties) The suffix is also used in the same OWNERMM.JAVA file, the content is as follows: // create by xslt generator for eclipse.// xsl: not found (java.io.filenotFoundException: (Bad file descriptor) //// DEFAULT XSL USED: Easystruts.jar $ org.easystruts.xslgen.javaclass.xslpackage com.sharp.struts.form;
Import javax.servlet.http.httpservletRequest;
Import org.Apache.struts.action.Actionerror; import org.apache.struts.Action.Apache.Struts.Action.Apache.struts.action.Apache.struts.Action.ActivityMapping;
/ ** * Ownerform.java created by Easystruts - xsltgen. * Http://easystruts.sf.net * created on 10-09-2004 * * xdoclet definition: * @struts: form name = "oownerform" * / public class Ownerform extends an actionform {// -------------------------------------------- ------------- Instance Variables
/ ** Email property * / private string email;
/ ** Greet Property * / private string greet = "mr.";
/ ** Address property * / private string address;
/ ** Tel Property * / private INT TEL = 0;
/ ** Name Property * / Private string name; // ------------------------------------- -------------------- Methods ... // getter, setter mothod, here
} 5, summarizing such an international small example can run, but the above write is rough, and it is necessary to have a certain understanding of Java and Struts. There are other practices on internationalization on the Internet, or you can refer to. If the above is biased, please ax