4

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?.

6
  • We need a little more information please. Commented Sep 28, 2009 at 4:53
  • From within a web browser, or as part of some server process? Commented Sep 28, 2009 at 5:10
  • 2
    lol at the quotes around "javascript" Commented Sep 28, 2009 at 5:12
  • 1
    I thought this community didn't make fun of people? Commented Sep 28, 2009 at 5:13
  • 2
    @ Joey if you don't know the answer you're the joke here,so please get lost. @ nickf I put quotes because to highlight it. Commented Sep 28, 2009 at 5:17

4 Answers 4

2

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

1

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.

Comments

1

HTML5 now allows JavaScript to read local files, via the File API:

http://www.html5rocks.com/en/tutorials/file/dndfiles/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.