wood burning stoves*
The moose likes JSP and the fly likes Changing variables dynamically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Changing variables dynamically" Watch "Changing variables dynamically" New topic
Author

Changing variables dynamically

Saulo Menezes
Greenhorn

Joined: Jan 15, 2003
Posts: 17
Hya!
At the moment I am trying to implement a small web site based on JSP and JavaScript with my group at university.
I have created some JavaBeans which keep information about some artists, the day they are to present a concert, the price of the tickets and how many there are available.
This information is brought back to the user once he makes any choice on his browser. The problem is that the number of tickets available is not changing dynamically. Actually this number is a JavaScript variable that always starts with the value 100.
I wonder how I could make this number change if every time a different user visits the page this number will be set to its first value, 100.
I would be grateful if one of you could give me some advice in this.
Yours,
Saulo
[ May 22, 2003: Message edited by: Saulo Menezes ]
Geeta Ramasami
Ranch Hand

Joined: Mar 05, 2003
Posts: 72
Hi,
If u r going to have a javascript variable it will be reinitialised for every browser refresh.
For reflecting the avaliable tickets u can follow 2 approaches.
1.One is after storing the ticket value in the database and after each user visits the site and books the tckt u can update the DB so that each user when chooses to view the available ticktes it would be the correct one.
2.Other is using application variable(putting the number of available tickets in the servlet context).This variable is available for all the users and when each user books a ticket u can update this variable value(ie current value minus 1).If a user chooses to look in for the number of available tckts he would get the current availablity taken from the servlet context.
Regards
Geeta
Debashish Chakrabarty
Ranch Hand

Joined: May 14, 2002
Posts: 226

You can also opt for generating the "javascript" dynamically. The initial value of "100" can be any value (say, incrementing on the last value fecthed from a query on your database). For ex:

HTH


Debashish
SCJP2, SCWCD 1.4
 
wood burning stoves
 
subject: Changing variables dynamically
 
Similar Threads
Servlet code for updating data in database
Passing huge string to JSP..
how to capture dynamically generated value
lock..read..modify..unlock
Calculating the number of tickets available