Ways to read a properties file in a JavaScript file __java

Source: Internet
Author: User
Tags i18n

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/

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.