Suppose that there is a JavaScript file called: readproperties.js, this file needs to read config.properties This configuration file, the steps are as follows:
1, download plugin jquery.i18n.properties-min-1.0.9.js, put in eclipse in the appropriate directory. Because of the need for jquery support, we also need jquery plug-ins, Select Jquery-1.7.1.min.js here (jquery.i18n.properties-min-1.0.9.js this plugin has no version requirements for jquery, you can use any version of the jquery plugin), as shown in the following illustration:
2, in the introduction of Readproperties.js JSP file to make the following statement: [HTML] view plain copy print? <script src= "Js/jquery-1.7.1.min.js" language= "JavaScript" > </script> <script type= "Text/javascript" src= "Js/jquery.i18n.properties-min-1.0.9.js" > </script>
<script src= "Js/jquery-1.7.1.min.js" language= "JavaScript" >
</script>
<script type= "text/" JavaScript "src=" Js/jquery.i18n.properties-min-1.0.9.js >
</script>
The path is adjusted according to the actual situation.
3. In Readproperties.js, write the following function to get the value in the properties file: [JavaScript] view plain copy print? function Loadproperties () {jQuery.i18n.properties ({//Load Properties file name: ' Ispindex ',//Properties file name Path: ' i18n/',//Properties file path mode: ' Map ',//Use the value in the resource file in the map callback:function () {//Set display after successful loading Alert ($.i18n.prop ("Isp_index"));//Isp_index is the key value of the data to be found in the properties file}}); }
function Loadproperties () {
jQuery.i18n.properties ({//Load Properties file
name: ' Ispindex ',//Properties file name
path: ' i18n/',//Properties file path
mode: ' Map ',//Use the value in the resource file in the map
callback:function () {//Set display after successful loading
Alert ($.i18n.prop ("Isp_index"));///Where Isp_index is the key value of the data to be found in the properties file}}
);
The path and name of the properties file need to be adjusted according to the actual situation. In this example, the properties file is placed in the following figure.
When you run this function, you can display the data you want.
If this article is not clear enough, you can refer to the API documentation: www.ibm.com/developerworks/cn/web/1305_hezj_jqueryi18n/