File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading properties file in javascript

 
Matt Thomassan
Ranch Hand
Posts: 44
  • 0
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • 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
    • 0
    • 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
    Author and ninkuma
    Marshal
    Pie
    Posts: 64173
    83
    IntelliJ IDE Java jQuery Mac Mac OS X
    • 0
    • 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
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Bear,

    Thank you so much for your guidance.

    I appreciate it.

    Thanks
     
    Don't get me started about those stupid light bulbs.
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic