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

read a property file to set variables using javascript

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I'd like to set some variables in a javascript by reading a properties file. Specifically, I need to determine the environment, like what server etc, various javascripts are operating in. This will be done on the server side.

How can I do this?

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:
  • Report post to moderator
What part are you having problems with? Reading a properties files? Generating Javascript using read-in values? What code have you already written?
 
Anne Forumer
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I just don't know how to read a property file using javascript!

Ultimately, I'd like to have a site-specific file which javascript scripts could use to set variables specific to that site. It may be done by reading or, somehow, "including" that file. I don't know much javascript.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
use an external javascript file
 
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:
  • Report post to moderator
You said:

This will be done on the server side.



then you said

I just don't know how to read a property file using javascript!



These are mutally exclusive.

You can read the server-side properties file in your servlet or JSP to produce the appropriate Javascript variable initializers with the values read from the properties file, or you can just include different JS files (not properties files) as Eric suggested.

You can't mix the two. Javascript has no access to the file system (either on the server or client side) and cannot read files of any type.
 
Anne Forumer
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I am using a third-party application which allows me to place my scripts only in a single file, common.js. I want to place the same file on each of my installations. However, I'd like scripts in common.js to refer to variables which will have installation-specific values.

What is the best way to accomplish this, given my constraints.

Thanks
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi Ranchers,

I am facing a similar 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 jdbcurl from the system.properties file?

Any suggestions are welcome.

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:
  • Report post to moderator
Same answer as given previously: you'll have to read the properties on the server side and create the appropriate JavaScript markup to send to the browser.
 
Matt Thomassan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi Bear,

Thanks for your prompt reply.

Can you give some example?

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:
  • Report post to moderator
Actually, since this is a sever-side issue, and because this original is over 4 years old, I'm going to ask you to re-post your request for examples in the JSP or servlets forum. It's rather off-topic for this one, and I can't move this older post.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic