File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » JSP
Bookmark "Changing variables dynamically" Watch "Changing variables dynamically" New topic

Changing variables dynamically

Saulo Menezes

Joined: Jan 15, 2003
Posts: 17
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.
[ May 22, 2003: Message edited by: Saulo Menezes ]
Geeta Ramasami
Ranch Hand

Joined: Mar 05, 2003
Posts: 72
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.
Debashish Chakrabarty
Ranch Hand

Joined: May 14, 2002
Posts: 231

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:


SCJP2, SCWCD 1.4, PMP, ITIL Foundation
I agree. Here's the link:
subject: Changing variables dynamically
jQuery in Action, 3rd edition