tags:

views:

761

answers:

3

How do I access a property file using javascript. Normally property file is a xml based file. I java we access a property file like this:

Properties prop = new Properties();
            fis = getClass().getResourceAsStream("props.xml");

            if (fis != null) {
                prop.loadFromXML(fis);
            }
String dbUrl = prop.getProperty("dburl");

I want to do the same but using javascript. is there a possible way of doing it?.

+2  A: 

JavaScript can't load files, as part of its security model. It can retrieve XML from the server using AJAX, but it can't read files from the client computer.

dj_segfault
+2  A: 

You can't load any files from the users computer with javascript in the browser.

If the file is from your own server you can load it, like any other ajax, with XMLHttpRequest.

Palo Verde
A: 

Javascript doesn't use property files, as, either it has all the information it needs in the javascript files or in the html, or it will make an XMLHTTPRequest call to get the information from the server.

The server can look at the property file, and may use information passed in from the request, such as the header information, to know more about the client, to determine what information to pass back.

So, if you want to pass back some localized information, the server would have to get that from the browser request and then it could send back just what is needed for that transaction.

Javascript is different from java, so one limit is that javascript cannot read from the hard drive of the user, and since it is a webpage, the user wouldn't have the property file installed, it would still be on the server.

Javascript can only make requests to the address that that script came from, so there is a second sandbox rule that has to be met.

You may want to better understand javascript, then try to rephrase your question.

James Black