Java itself supports multi-language coding. You don't need to write any procedures, you can make it easy. The secret is two points:
1, all HTML / JSP pages are all UTF-8 encoding
2, client browser fully supports UTF-8 encoding
Steps: 1, first set all the HTML / JSP ContentType to UTF-8
2, and then you should be written in the program for the non-ASCII code prompt in the JSP program, and should be managed in Application.properties.
3. Do HTML with the Native2ASCII tool unified to handle, convert the non-ASCII code in HTML to Unicode encoding.
4. For different languages, write different application.properties, such as Simplified Chinese is Application_ZH_CN.Properties, Traditional Chinese is Application_ZH_TW.Properties This, then use the Native2ASCII tool to handle it once, non-ASCII chi Go to Unicode encoding.
5. Get the client's operating system default encoding, then set to the httpsession of the Struts.
OK! Different customer visits are now displayed different languages. You can look at the character set of your browser at this time, is UTF-8. Now your website is the same as Google, hey, in fact, what is your browser to visit Google?
Remember: All HTML / JSPs are set to UTF-8 encoding, and the non-ASCII code characters in all files must be converted to Unicode encoding represented by ASCII. --------------------------------------- above is the one I am from the Internet The solution in Chinese issues, it is exactly that it should be about Struts' internationalization. Below I combined with my practice talk about how to implement Struts internationalization, I am not very proficient in theory, I can only pay hard Understanding and practice, so the content below may not be very correct, please forgive me. But one thing can be sure, I solved the Chinese problem of Struts through my own efforts, and realize the internationalization of Struts. In fact, everything is not complex, the following is the specific step:
0. The problem encountered (these issues may not appear at the same time) a. The Chinese data becomes "????" b. Do a good Chinese Properties file, where Chinese Value is The page shows the Chinese to the browser in garbled C.JSP file, it is also garbled when it is displayed (it is recommended not to enter Chinese in the JSP file, try to put it in the Properties file) d. By the JSP passed to the Chinese value, then pass it by bean The page is also garbled E. When replacing the local browser language option, the web application cannot automatically select the appropriate * .properties file according to your LOCALE. Leading web applications cannot be international. 1. Environment: Web Server: Tomcat 5.0.19 Operating System: WIN2000 Server JVM: JDK 1.4 Database: Oracle 8.1.7 Development Tools: Struts Studio 5.2 Pro for Eclipse 2. Add all * .jsp web pages <% @ Page language = "java" contenttype = "text / html; charset = UTF-8"%> Set
3. Then edit the two * .properties files, place them under the Classes folder, here is placed in / web-inf / class / com / wiley, they are:
ApplicationResources.properties (English) ApplicationResources_ZH.Properties (Chinese resource file) is used to write all the tools! 4. Transcode ApplicationResources_ZH.Properties into GB2312. The above citation said to be transferred into UTF-8, and I tried it, no. It is possible to turn into GB2312, and the operation is. The ApplicationResources_zh.properties renamed ApplicationResources_xx.properties in the DOS command line enter the folder where the file ApplicationResources_xx.properties use the command: native2ascii -encoding gb2312 ApplicationResources_xx.properties ApplicationResources_zh.properties (As to why you will "native2ascii is not an internal command" ,, please check Other information, maybe you have to set an environment variable because he is an application under the JDK folder bin) 5. Configure struts-config.xml, which is very simple, we join:
This has been able to solve most Chinese issues. As mentioned above, the A, B, E now open the browser, select the menu: Tool "Internet Option" language, "Chinese-China [ZH-CN]" delete, add a "English-British [zh-gb] "After confirming, restart Tomcat, enter the URL. You will find that your page text information will be used in the ApplicationResources.properties (English resource file). If you change back, "Chinese-China [EN]", it will display the Chinese content in the ApplicationResources_zh.properties (Chinese resource file). As for problems "C. JSP files are also garbled when they are displayed after the browser" "You have to use a similar method similar to the fourth step to the * .jsp file encoding, then -Encoding parameters will use UTF- 8. If you use the Struts Studio 5.2 Pro for Eclipse tool, this step is free. It automatically stores the format of UTF-8. As for the problem "D. The Chinese value passed by JSP to bean, and then it is solved by the bean transfer to the page again", I just add a filter. You can now join:
Then I add a Java file in the package you specified. I am in / web-inf / class / com / wiley, below is the source code: / ** xp forum * * CopyRight (C) 2002-2003 Redsoft Group. All Rights reserved. ** / package com.huahang.tj.struts.filters;
Import javax.servlet. *; import java.io.ioException;
/ ***
Filter that sets the character encoding to be used in parsing the * incoming request, either unconditionally or only if the client did not * specify a character encoding. Configuration of this filter is based on * the following initialization parameters : p> *
ignore code> initialization Parameter. this parameter * is Required, So there is no default. li> * - ignore strong> - if set to "true", any character encoding * Specified by the client is ignored, and The value returned by the *
selectEncoding () code> method is set. if set to "false, * selectencoding () code> is caled only strong> if the * Client Has Not Already Specified An Encoding. by Default, this * Parameter Is Set to "True". li> * ul> ** although this filter can be used unchanged, it is also easy to * Subclass IT and make the se lectEncoding () code> method more * intelligent about what encoding to choose, based on characteristics of * the incoming request (such as the values of the Accept-Language code> * and User-Agent code> Headers, or a value stashed in the current * user's session. p> ** @Author John wong ** @version $ ID: setcharacterencodingfilter.java, v 1.1 2002/04/10 13:59:27 Johnwong Exp $ * / public class setcharacterencodingfilter imports filter {
/ / -------------------------------------------------------------------------------------------- ----- Instance Variables / *** The default character encoding to set for reviews That pass through * this filter. * / Protected string encoding = null;
/ *** The filter configuration Object We are associated with. If this value * is null, this filter instance is not currently configured. * / Protected filterconfig filterconfig = null;
/ *** SHOULD a CHARACTER ENCODING SPECIFIED BY THE CLIENT BE IGNORED? * / Protected boolean ignore = true;
/ / -------------------------------------------------------------------------------------------- --------- Public Methods
/ *** Take this filter out of service. * / Public void destroy () {
THIS.Encoding = null; this.filterconfig = NULL;
}
/ *** Select and set (if specified) the character encoding to be used to * interpret request parameters for this request. ** @param request The servlet request we are processing * @param result The servlet response we are creating * @param chain The filter chain we are processing ** @exception IOException if an input / output error occurs * @exception ServletException if a servlet error occurs * / public void doFilter (ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
// Conditionally select and set the character encoding to be usedif (ignore || (request.getCharacterEncoding () == null)) {String encoding = selectEncoding (request); if (! Encoding = null) request.setCharacterEncoding (encoding); }
// Pass Control on to the next filterchain.dofilter (request, response);
}
/ *** Place this filter into service. ** @Param filterConfig the filter configuration Object * / public void init (FilterConfig filterConfig) throws servletexception {
this.filterConfig = filterConfig; this.encoding = filterConfig.getInitParameter ( "encoding"); String value = filterConfig.getInitParameter ( "ignore"); if (value == null) this.ignore = true; else if (value.equalsIgnoreCase ("True")) this.ignore = true; Else IF (Value.equalsignorecase ("YES")) this.ignore = true; elsethis.Ignore = false;}
/ / -------------------------------------------------------------------------------------------- ------ Protected Methods
/ *** Select an appropriate character encoding to be used, based on the * characteristics of the current request and / or filter initialization * parameters. If no character encoding should be set, return * null code>. * * The default implementation unconditionally returns the value configured * by the encoding strong> initialization parameter for this * filter. ** @param request The servlet request we are processing * / protected String selectEncoding (ServletRequest request) {
Return (this.encoding);
}
} // eoc here I have all the Chinese issues have been resolved and learned from the deep meaning of the internationalization of Struts. I personally think that Struts as a powerful application framework should take into account its internationalization, and it will not be very complicated in practical applications. As long as we follow some rules, we can enjoy Struts to bring us. pleasure. I hope that the above will help you.