Link to home
Start Free TrialLog in
Avatar of cgray1223
cgray1223

asked on

Read Property Value in JavaScript File

Hello,

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

${test.key}
Avatar of for_yan
for_yan
Flag of United States of America image


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?
Avatar of cgray1223
cgray1223

ASKER

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
Avatar of Mick Barry
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
ASKER CERTIFIED SOLUTION
Avatar of Sathish David  Kumar N
Sathish David Kumar N
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial