Skip to content Skip to sidebar Skip to footer

Read Properties File Using Jquery Or Javascript

I am newbie in jquery. I would like to read Java properties file in my jsp page using javascript or jquery. I'm goggling about it but not satisfied. My application is developed b

Solution 1:

One shouldn't use scriptlets in JSP, you can easily do it using struts2 tags.

Change your Javascript in JSP as follows :

functioncheckedRadioForDelete(f) {
    var chx = document.getElementsByTagName('input');
    for ( var i = 0; i < chx.length; i++) {
        if (chx[i].type == 'radio' && chx[i].checked) {
            var con = confirm("<s:text name="msg.confirm"/>");
            if (con != true) {
            } else {
               f.action = "MyAction.action";
               f.submit();
             }
            returntrue;
         }
    }
    alert("<s:text name="msg.alert"/>");
    returnfalse;
 }

Solution 2:

You can load properties with javascript using messageResource.js library created by me.

1) Include messageResource.js.

<scriptsrc="messageResource.min.js"></script>

2) Change javascript as follows.

// initialize messageResource.js  
messageResource.init({
    // path to directory containing properties files
    filePath : 'path/resource'
});

function checkedRadioForDelete(f) {

    // get values from properties filesvar confirmMsg = messageResource.get('msg.confirm', 'fileName');
    var alertMsg = messageResource.get('msg.alert', 'fileName');

    var chx = document.getElementsByTagName('input');
    for ( var i = 0; i < chx.length; i++) {
        if (chx[i].type == 'radio' && chx[i].checked) {
            var con = confirm(confirmMsg);
            if (con != true) {
            } else {
                f.action = "MyAction.action";
                f.submit();
            }
            returntrue;
        }
    }
    alert(alertMsg);
    returnfalse;
}

Solution 3:

Note: Updating my answer based on comments.

In your JSP page you can use scriptlets within javascript function (or tag) 

functioncheckedRadioForDelete(f) {
    var confirmMessage = '<%= properties.getProperty("confirm.message") %>';
    var alertMessage= '<%= properties.getProperty("alert.message") %>';
            var chx = document.getElementsByTagName('input');
            for ( var i = 0; i < chx.length; i++) {
                if (chx[i].type == 'radio' && chx[i].checked) {
                    var con = confirm(confirmMessage);
                    if (con != true) {
                    } else {
                       f.action = "MyAction.action";
                       f.submit();
                     }
                    returntrue;
                 }
            }
            alert(alertMessage);
            returnfalse;
         }

Solution 4:

If anyone needs help for a Web Application, please see my answer that explains the simplest method to read properties from a property file in the project directory. In summary, you will be able to populate some selected properties in hidden inputs and then read the hidden input value from JavaScript.

Post a Comment for "Read Properties File Using Jquery Or Javascript"