• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reading properties file in javascript

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
     
    Matt Thomassan
    Ranch Hand
    Posts: 44
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Sheriff
    Posts: 67746
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 44
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Bear,

    Thank you so much for your guidance.

    I appreciate it.

    Thanks
     
    That feels good. Thanks. Here's a tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic