This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Can javascript files shared variables across multiple instances of an application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Can javascript files shared variables across multiple instances of an application" Watch "Can javascript files shared variables across multiple instances of an application" New topic
Author

Can javascript files shared variables across multiple instances of an application

Vijay Vincent
Greenhorn

Joined: Nov 24, 2004
Posts: 3
Hi,
I have an jsp application containing 6 jsp files. I have refresh a page when there is change in data. For eg, if user A and B logged in. If user A changes a data, then after some time, user B should see the change. one jsp(say X) page displays all data with HREF. On clicking the reference, it takes to another jsp(say Y) page to update/delete. I want to set a shared (say sv)variable in page Y, so that when there is update, sv is set to 1. On page X, I want to use setTimeOut to recursively check for this sv variable, if 1, then I set sv=0 and refresh the page, otherwise not.

1. Is there any shared variable concept in javascript?
2. or if I use java static variable, how can I use this in javascript function.

Any help is highly appreciate!!! It is very urgent!!!
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
JavaScript can not access variables across the differentcomputers. The best thing is to use Java to write the variable to the page so JavaScript can access it.

Eric
Vijay Vincent
Greenhorn

Joined: Nov 24, 2004
Posts: 3
Ok, If you see one of my question,how javscript can use java variable.
For eg, If I decide to have static variable in java, how this variable is read in javascript function.

Any help is highly appreciated!!!
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You need to have the Java on the server write it to the page when it is loading.
Vijay Vincent
Greenhorn

Joined: Nov 24, 2004
Posts: 3
Thanks for the reply, But I have to keep on reading this static variable in a loop, so that when there is change, this static variable will be set to 1. And the loop in javescript using setTimeout will check whether this static variable is 1, if 1 then refresh the page and continue checking. Note: this static variable is set to 1 in one page. While looping is done in another page.
So in this case how to use java static variable in javascript function.
[ November 28, 2004: Message edited by: Vijay Vincent ]
Yuriy Fuksenko
Ranch Hand

Joined: Feb 02, 2001
Posts: 413
1. JSP is executed on a server
2. JSP writes a text which is submitted to a client. (I would really suggest you to look at the java class created by server from your JSP)
3. Browser reads a text and builds an HTML page.
4. JavaScript is part of that HTML page, and executed by browser on client machine.
5. The way JavaScript access variables from Java code is you write them into the page as part of the text from #2.
6. the value will not be updated without page reloading. (I mean something should hit a server - frame, iframe, page itself)
7. Static Java variables will not work well with clustering.
 
 
subject: Can javascript files shared variables across multiple instances of an application
 
Similar Threads
How can a non-servlet find application root and best way to access a servlets data?
session issues with Ctrl-N
java check box
Web Application Shared Amongst many users
REFRESF BROWSER