Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 406
  • Last Modified:

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}
0
cgray1223
Asked:
cgray1223
1 Solution
 
for_yanCommented:

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?
0
 
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?
0
 
for_yanCommented:
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
0
 
objectsCommented:
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
0
 
Sathish David Kumar NCommented:
you can use foramt tag....
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now