Java:jsp:ResourceBundle International Multi-lingual

Source: Internet
Author: User
Tags locale stub

Java provides a resource class Java.util.ResourceBundle to try out multi-lingual versions. In fact ResourceBundle is just an abstract class, she has two sub-classes: ListResourceBundle, and, propertyResourceBundle. The previous subclass needs to write different national language information placed in the object class, the following example shows that the latter subclass is a file suffix that needs to be written in a different country language. Properties () to hold the language information, this part of the reader can be in the internationalization tag and Stru TS is known. For example, a res_en_us.properties resource file that is stored in Res_zh_en.propertieh and stored in English.

1 Package Cn.com.resouce;2 import Java.util.ListResourceBundle;3 4  Public classRes_zh_cn extends ListResourceBundle {5 6     StaticFinal object[][] Contents =Newstring[][]{7{"version","This is the Chinese version"},8{"title","Chinese version"},9{"Index","Home Page"},Ten{"News","News"}, One{" Life","Life"}, A{"Sports","Sports"}, -{"Entertainment","Entertainment"} -     }; the      -      - @Override -     protectedobject[][] getcontents () { +         //TODO auto-generated Method Stub -         returncontents; +     } A  at}

1 Package Cn.com.resouce;2 import Java.util.ListResourceBundle;3 4  Public classRes_en_us extends ListResourceBundle {5     6     //create a corresponding Chinese text message7     8     StaticFinal object[][] Contents =Newstring[][]{9         Ten{"version","This is中文版"}, One{"title","中文版"}, A{"Index","Index"}, -{"News","News"}, -{" Life"," Life"}, the{"Sports","Sports"}, -{"Entertainment","Entertainment"} -     }; -  +  - @Override +     protectedobject[][] getcontents () { A         //TODO auto-generated Method Stub at         returncontents; -     } -  -}

select.jsp

1<%@ page language="Java"Contenttype="text/html; Charset=utf8"%>2<! DOCTYPE HTML Public"-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD">345<meta http-equiv="Content-type"Content="text/html; Charset=utf-8">6<title> language Selection </title>78<body>9 Ten  One<form action="multilanguage.jsp"Method="Get"> A<SelectName="language"> -<option name="default"> Default </option> -<option value="Chinese"> Chinese </option> the<option value="中文版">English</option> -</Select> -<input type="Submit"Value="Submit"> -</form> +  -</body> +

language.jsp

<%@ page language="Java"Contenttype="text/html; Charset=utf8"%><%@ page import="Java.util.resourcebundle,java.util.locale"%><%String Language= Request.getparameter ("language");//default language, the browser will identify the default language based on the accept language included in the requestResourceBundle res = Resourcebundle.getbundle ("Cn.com.resouce.RES");//Chinese version of the displayif(Language.equals ("Chinese") ) {res= Resourcebundle.getbundle ("Cn.com.resouce.RES",NewLocale ("ZH","CN")); }if(Language.equals ("中文版") ) {res= Resourcebundle.getbundle ("Cn.com.resouce.RES",NewLocale ("en","US")); }%><! DOCTYPE HTML Public"-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD">"Content-type"Content="text/html; Charset=utf-8"><title><%=res.getstring ("title")%></title>"version")%>"Index")%> | <%=res.getstring ("News")%> |<%=res.getstring (" Life")%>| <%=res.getstring ("Sports")%> | <%=res.getstring ("Entertainment")%></body>

Java:jsp:ResourceBundle International Multi-lingual

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.