JSP multi-language first

Source: Internet
Author: User

Take the jsp page title as an example:

To read multiple languages, you must put them in properties and return their values by reading the key corresponding to properties in the background. Then, the jsp page needs to introduce the class:


<% @ Page import = "com. mytest. sys. config. sysTextConfig "%> <% @ page import =" com. mytest. sys. config. sysTextConfig "%> here the SysTextConfig class handles multiple languages
<Title> <% = extends extconfig. getConfigInfo ("bsd_text") + extends extconfig. getConfigInfo ("title") %> </title> <% = extends extconfig. getConfigInfo ("bsd_text") + extends extconfig. getConfigInfo ("title") %> </title> the content of the SysTextConfig class is

Public class extends extconfig {private static Properties properties = null; // read the properties resource file private static long lastModified = 0; // The last modification time in the memory: long TYPE private static String filePath = null; // the absolute path of the properties File to be saved: private static File sysConfigFile = null; static {// initialize the value of the static variable StringBuffer configFilePath = new StringBuffer (); String classPath = javasextconfig. class. getClassLoader (). getResource (""). getPath (); S Tring weninfoPath = classPath. substring (0, classPath. lastIndexOf ("classes"); configFilePath. append (weninfoPath ). append ("config"); configFilePath. append (File. separator ). append ("cmdext. properties "); filePath = configFilePath. toString ();} private static boolean isNotlastModified () {sysConfigFile = new File (filePath); if (sysConfigFile. lastModified ()! = LastModified) return true; return false;} private static void loadSysConfigFile () {properties = new Properties (); FileInputStream fileInputStream; try {fileInputStream = new FileInputStream (sysConfigFile); properties. load (fileInputStream);} catch (Exception e) {// TODO Auto-generated catch block e. printStackTrace () ;}} public static String getConfigInfo (String key) {// function entry. First, verify Last modification time. if it is not set to 0, it indicates that it has been modified. Then, it is required to load loadSysConfigFile if (isNotlastModified () loadSysConfigFile (); Object object = properties again. get (key); // String value = "" to read properties; try {if (StringUtils. isNotEmpty (object) {value = new String (object. toString (). getBytes ("ISO8859_1"); // return its value through the key} catch (UnsupportedEncodingException e) {e. printStackTrace ();} return value;} public class extends extconfig {private st Atic Properties properties = null; // read the properties resource file private static long lastModified = 0; // The last modification time in the memory long private static String filePath = null; // Save the absolute path of the properties File private static File sysConfigFile = null; static {// initialize the value of the static variable StringBuffer configFilePath = new StringBuffer (); String classPath = javasextconfig. class. getClassLoader (). getResource (""). getPath (); String weninfoPath = classPath. substrin G (0, classPath. lastIndexOf ("classes"); configFilePath. append (weninfoPath ). append ("config"); configFilePath. append (File. separator ). append ("cmdext. properties "); filePath = configFilePath. toString ();} private static boolean isNotlastModified () {sysConfigFile = new File (filePath); if (sysConfigFile. lastModified ()! = LastModified) return true; return false;} private static void loadSysConfigFile () {properties = new Properties (); FileInputStream fileInputStream; try {fileInputStream = new FileInputStream (sysConfigFile); properties. load (fileInputStream);} catch (Exception e) {// TODO Auto-generated catch block e. printStackTrace () ;}} public static String getConfigInfo (String key) {// function entry. First, check the last modification time of the properties file, if the value is not 0, it indicates that it has been modified. Then, the loadSysConfigFile if (isNotlastModified () loadSysConfigFile (); Object object Object = properties will be loaded again. get (key); // String value = "" to read properties; try {if (StringUtils. isNotEmpty (object) {value = new String (object. toString (). getBytes ("ISO8859_1"); // return its value through the key} catch (UnsupportedEncodingException e) {e. printStackTrace ();} return value ;}}

 

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.