• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Reading properties file in javascript

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • 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
 
Marshal
Posts: 67356
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • 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
    • 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
    Marshal
    Posts: 67356
    173
    Mac Mac OS X IntelliJ IDE jQuery Java
    • Mark post as helpful
    • send pies
    • 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
    • Quote
    • Report post to moderator
    Hi Bear,

    Thank you so much for your guidance.

    I appreciate it.

    Thanks
     
    He's giving us the slip! Quick! Grab this tiny ad!
    Java file APIs (DOC, XLS, PDF, and many more)
    https://products.aspose.com/total/java
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!