This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JSP and the fly likes Reading properties file in javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "Reading properties file in javascript" Watch "Reading properties file in javascript" New topic
Author

Reading properties file in javascript

Matt Thomassan
Ranch Hand

Joined: Dec 23, 2008
Posts: 44
Hi Ranchers,

I am facing a problem.

In my web application, I have a properties file that has many name-value pairs.

I want to use the names in properties file in a javascript function.

Eg:
1)
system.properties file:
jdbcurl = jdbcracle:thin:@myhost.com:1520:TID007z

2) javascript function:
function testfunction(jdbcurl){
var connectionurl=jdbcurl;
// some processing with connectionurl
}


So, how can i load the value of jdbcurl in the javascript function from the system.properties file?

Any suggestions are welcome.

Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61314
    
  66

Read the properties on the server and emit JavaScript markup.

One way I've done in the past:

  • In a context listener, read in the properties and create a Map implementation of the name/value pairs
  • Place the Map in application scope
  • on a JSP page, reference the Map to grab any (or all) properties and their values

  • This assumes that the properties aren't expected to change over the life-cycle of the application.


    [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
    Matt Thomassan
    Ranch Hand

    Joined: Dec 23, 2008
    Posts: 44
    Hi Bear,

    Thanks for your reply.

    Once we have put the Map of name value pair in the application scope, JSP can retrieve them.

    But how do I get them into a javascript function?

    I am sorry if it is a trivial question.

    Thanks
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61314
        
      66

    Let's say that the Map that you put into the application scope is named myPropertiesMap, and you want to retrive a property value with a key of xyz.

    In your JSP:


    Remember, your JSP is just a template for the HTML to be sent to the browser.

    Matt Thomassan
    Ranch Hand

    Joined: Dec 23, 2008
    Posts: 44
    Hi Bear,

    Thank you so much for your guidance.

    I appreciate it.

    Thanks
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Reading properties file in javascript