Read Property Value in JavaScript File


I have a properties file in my Java web application that consists of key/value pairs and gets placed in the classpath so my application can ready configuration values from it.  I can't figure out how my JavaScript files can read the values, given the keys of the properties file.  I would like to have a 100% configurable application and not have to hardcode any string values in my JavaScript files.  I access the values of the properties file like below for xml files....

Who is Participating?
Sathish David Kumar NArchitectCommented:
you can use foramt tag....

You are writing that you have Java Web application - so it uses servlets or JSP
pages or somthing of the sort?

So you mean you JavaScript will be created in your servlet code?

Could you please, elaborate a little more on your architecture - how
does your Java Web application relates to the javaScript which you are mentioning?
cgray1223Author Commented:
I have a JSF based application that runs on tomcat, so its a Java based application that conforms to the Servlet spec....It has html pages...etc.  Some of my html pages include a javascript function.  In that function it has the need for some default values, like a url or a redirect..etc.  I would like to externalize those values instead of baking them into the javascript.  I have a .properites (ResourceBundle) in the Java classpath that I can call from Java or xml, is there a way to call it from a js function?
It is probably something rather difficult - muind that your javascript executes on the client,
and your property file is on the server.
So inless you want to send the whiole of your property file somehow with the web page to
the client you'd hardkly be able to read it directly from javascript.

You can read it before when preparing the page and include the value in the page - that is waht you don't want

You can set up some ajax like connection back to server from your java script and web service would return to java script
the value, but that seems to be like an overkill
you can use jsf/jsp/servlet to generate the javascript the same way you generate html
just map the js path to the appropriate backend component
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.