<% = lss.getstring (" form.label ")%> label> "> form> body> html> Beans.localstrings source files are as follows:
Package beans;
import java.util.ResourceBundle; import java.io.UnsupportedEncodingException; import java.util.Locale; public class LocalStrings {protected ResourceBundle rb; protected boolean encoded; public LocalStrings (String baseName, Locale locale) {this.rb = ResourceBundle.getBundle (BaseName, Locale); if (Locale.getCountry (). Equals ("CN") || Locale.getCountry (). Equals ("tw") Encoded = true;} public string getstring (string key) {String Value = rb.getstring (key); if (encoded) {Try {byte BS [] = value.getbytes ("ISO-8859-1"); Return New String (BS, "GBK");} catch (unsupportedEncodingexception UEE) {Return Value;}} Return Val UE;}} Access to Form.jsp from the browser, we should see the correct output, and then set the browser language into "Chinese (Taiwan) [zh-tw]" by browseing the Internet option, and then access the Form. JSP, we can see the prompt information of the traditional Chinese; then set the browser language "English (US) [EN-US]", and then access Form.jsp. Why use localstrings to re-encode these strings, see the resourcebundle's source program that can be found when it reads the file, and we have to encode the string, so we have to be related to the correct encoding in localstrings. String code. Five, some suggestions
We have developed by J2EE (Java 2 Enterprise Edition, Java 2 Enterprise Edition), which may be transplanted between some servers that support J2EE specification, and platforms for these servers may also be different. Our client's operating system or browser used is also possible, so we should strive to follow some suggestions:
l Depending on the user's operating system, browser, and language in the request head, and use the appropriate method to perform the setting of the CHARSET in the corresponding response head.
l Try not to use a constant string containing non-English characters in the servlet. l For JSP files, as long as there is a constant string containing non-English characters that are not ignored by the server, the PageEnCoding property in the Page Ins should be set accordingly.
l Use the filter to set
ServletRequest.setCharateRencoding;
To set the encoding of the request entity instead of setting it in each JSP or Servlet. Abandoning the habit of setting Content-Type in servlet, let the filter pass according to different resources and user objects
ServletResponse.setContentyType (String Type);
To set it.
l Try to use UTF-8 as encoding instead of GBK or GB2312.
l Follow the encoding used by the underlying database, it may cause trouble in the transplant of the application.
l The encoding used by the data used by the user browser encoding is not easy to effectively and effectively. It is a regret that the programmer is extended, and the ENCTYPE of the FORM element is modified, so that this property is fully compatible with MIME The development of Charset, web applications has fewer troubles.
Appendix A. All experiments in this article are as follows:
l operating system MS Windows 2000 Server
l Area Setting Chinese (China)
l System Language Chinese (Simplified) Default
l Browser Microsoft Internet Explorer 6.0B
l Java virtual machine J2SDK 1.4.0-B92
l Java server Apache Tomcat 4.0.4
Appendix B. Reference:
1. Java technology and its application / Wang Kehong editor; Dong Liquan. - Beijing: Higher Education Press, 1999 (2001)
2. JSP Programming Guide (Second Edition) / (US) Brown (BROWN, S.) is waiting; Wang Jun and other translations. - Beijing: Electronic Industry Press, 2002.10 (Wrox programmer Reference Series) title Original: Professional JSP 2nd Edition
3. JSP site Design Programming Guide / (US) Dufei (Duffey, K.) is waiting; Wang Jun and other translations. - Beijing: Electronic Industry Press, 2002.7 (Wrox programmer reference series) Original: Professional JSP Site DESIGN
4. J2EE Server Advanced Programming Guide / (US) Allamaraju, S.) is waiting; Wenjing Study Interpretation. - Beijing: Machinery Industry Press, 2001.9 (Wrox Programmer Reference Series) : Professional Java Server Programming J2ee Edition
5. XML Advanced Programming (Second Edition) / (English) Burbeck (Birbeck, M.) Waiting; 裴 Jianfeng and other translations. - 2 Edition. - Beijing: Machinery Industry Press, 2002.5 (Wrox programmer reference series) Site: Professional XML 2nd Edition6. Java Programming Ideology (English Edition · 2nd Edition) / (US) Ecr (Eckel, B.). - Beijing: Machinery Industry Press, 2002.1 (Classic Original Book) Book Name original: Thinking in java (Second Edition)
7. XSL technology practice - Just XSL / (US) Senpasson (SIMPSON, J.E.); Peng Shi'an and other translations. - Beijing: Machinery Industry Press, 2002.7 (Internet New Technology Book) title Original: Just XSL
8. Java network programming technology insider / (US) Hughes, M.); Liu Yong's first translation. - Beijing: National Defense Industry Press, 2002.3 (Programming Classic Translation) Substitation Original: Java NetWork Programming
9. Java TM 2 SDK, Standard Edition Documentation Version 1.4.0.
-Sun Microsystems, Inc.
10. HTML 4.01 Specification. -W3c, 1999.12.24.
http://www.w3c.org/tr/html401/html401.html
11. Hypertext Transfer Protocol - HTTP / 1.1 / Field, R) is waiting. -Ietf, 1999.6. Http://www.ietf.org/rfc/rfc2616.txt
12. Java Chinese Processing Learning Notes - Hello Unicode / Car East. -9CBS_Documentation Center
13. JavaScript complete manual / (US) Powell (Powell, T.) is waiting; Buffali and other translations. - Beijing: Electronic Industry Press, 2002.7 (Full Manual Book) title Original: JavaScript: The Complete Reference
Author Blog:
http://blog.9cbs.net/WhodSow/