Display Updated/changed value(from cache) in JSP

B

Buddha

Dear all,

I did post this on the sun forum with out too much help. I am assuming
I shall be lucky enough to get some here.
Since I am clueless on how I wish to do it, I do not really have
anything that I have done.
This is part of my problem

What I am doing is : Displaying the value (price of an item) from the
database on to a JSP.
The price of the item can be changed. I am putting that in a cache
(because only the final updated price goes to the db) and then; what I
need to do it : to display this updated price (from the cache) in all
browsers that are currently "seeing" this JSP, without having to
refresh the jsp, i.e.

I have dabbled with ajax, however I am stuck at : the Jsp can make an
async. call to the servlet, but how do I make the servlet send the
changed value to the jsp.

to put across my point in a more clearer way.
There is a timer running.
You can think Its like an auction site which multiple people would
access. they could change values (prices, amounts they would enter as
a bid). If a user A enters an amount then that should be displayed to
other users logged in too. Users B,C and D should be able to see the
changed amount, which means B,C and D('s browsers) should be
automatically updated. They wouldnt be making any requests to the
server.
What ways could I explore to achieve this behaviour ?

I would appreciate if some one could point me to a direction.

Rgds,
 
G

GArlington

Dear all,

I did post this on the sun forum with out too much help. I am assuming
I shall be lucky enough to get some here.
Since I am clueless on how I wish to do it, I do not really have
anything that I have done.
This is part of my problem

What I am doing is : Displaying the value (price of an item) from the
database on to a JSP.
The price of the item can be changed. I am putting that in a cache
(because only the final updated price goes to the db) and then; what I
need to do it : to display this updated price (from the cache) in all
browsers that are currently "seeing" this JSP, without having to
refresh the jsp, i.e.

I have dabbled with ajax, however I am stuck at : the Jsp can make an
async. call to the servlet, but how do I make the servlet send the
changed value to the jsp.

to put across my point in a more clearer way.
There is a timer running.
You can think Its like an auction site which multiple people would
access. they could change values (prices, amounts they would enter as
a bid). If a user A enters an amount then that should be displayed to
other users logged in too. Users B,C and D should be able to see the
changed amount, which means B,C and D('s browsers) should be
automatically updated.
They wouldnt be making any requests to the server.

With standard HTTP - NO WAY, the server can not push anything to the
client without a request.
You can embed <applet> (or similar) in your page, and then this applet
will maintain connection with the server - this is NOT a good practice
though -> if you have a lot of clients (imaging everybody in your city
trying to login at once) you will run out of connections on your
server(s).
So you will have to make periodic requests to the server (via AJAX is
one of the options) for updates from each client.
 
G

gwoodhouse

There is a timer running.

I'm not sure if you have tried this but;

Why not create a javascript timer, one that sends a request to a
servlet every few seconds/minutes (depending on your capacity/server
load). In this way the response could give the value of the field you
need.

Ive done something similar in the past, but at a previous company so i
can't copy paste code im afraid. I managed it with the references at
w3schools. Great site that.

Hope that helps,

Graeme
 
B

Buddha

I'm not sure if you have tried this but;

Why not create a javascript timer, one that sends a request to a
servlet every few seconds/minutes (depending on your capacity/server
load). In this way the response could give the value of the field you
need.

Ive done something similar in the past, but at a previous company so i
can't copy paste code im afraid. I managed it with the references at
w3schools. Great site that.

Hope that helps,

Graeme


Hi,

thanks for your replies.
make periodic requests to the server (via AJAX is
Well, thats the point. Assume 5 browsers have established a session
with the web server.
now 1 of them has bid his amount, whcih is, changed the current price
value. THIS, can be posted to the server.Also can be done using AJAX.
However, I would also want to update the rest of the 4 browsers with
the latest update of the price.
Why not create a javascript timer, one that sends a request to a
servlet every few seconds/minutes (depending on your capacity/server
load). In this way the response could give the value of the field you
need.

The seconds part is what I also thought about; because this is a
auction site and all users got to be updated asap. However, I am
afraid, I dont know if it is a good solution.
Wont it increase the traffic, slow down the performance and restrict
the number of users I can have ?
I have heard a lot of stock tickers work the same way. Any clue on how
they function ?


thanks
 
L

Lew

Buddha said:
Hi,

thanks for your replies.
Well, thats the point. Assume 5 browsers have established a session
with the web server.
now 1 of them has bid his amount, whcih is, changed the current price
value. THIS, can be posted to the server.Also can be done using AJAX.
However, I would also want to update the rest of the 4 browsers with
the latest update of the price.

Right. Did you have a question there? Why wouldn't Graeme's suggestion work
for you?

The basic pattern for a resource manager (your server manages the resource of
common knowledge) is to have it answer only, and let the resource consumers be
request only.

The resource manager "holds" the request until it has an answer. So on the
"status" channel all /n/ clients request session status, but do not get an
answer right away. When one of the clients makes a change (a new bid), it
pushes the change on the "change" channel. The server then answers all /n/
requests for status with the new data over their respective "status" request
channels. When the clients receive their status data, they immediately make a
new request for the next status over their respective "status" channels.
Continue until shampoo bottle is empty.

--
Lew
public void washHair( ShampooBottle bottle ) throws EmptyBottleException
{
do { wash(); rinse(); } while ( repeat );
}
 
D

Daniel Pitts

Hi,

thanks for your replies.>make periodic requests to the server (via AJAX is

Well, thats the point. Assume 5 browsers have established a session
with the web server.
now 1 of them has bid his amount, whcih is, changed the current price
value. THIS, can be posted to the server.Also can be done using AJAX.
However, I would also want to update the rest of the 4 browsers with
the latest update of the price.


The seconds part is what I also thought about; because this is a
auction site and all users got to be updated asap. However, I am
afraid, I dont know if it is a good solution.
Wont it increase the traffic, slow down the performance and restrict
the number of users I can have ?
I have heard a lot of stock tickers work the same way. Any clue on how
they function ?

thanks

Also look into cometd.
It is an AJAX like technology that lets you "push" values to the
clients.

In practice though, you should make every attempt to inform the
customer that the value has changed, but don't assume that they were
informed before they made an action (the value could have changed
between the time they pressed the mouse button and the browser
registered it).
 
B

Buddha

Also look into cometd.
It is an AJAX like technology that lets you "push" values to the
clients.

Thanks. am gonna take a look at it now.
Right. Did you have a question there? Why wouldn't Graeme's suggestion work
for you
I did :
slow down the performance and restrict
the number of users I can have ?
I have heard a lot of stock tickers work the same way. Any clue on how
they function ?


I guess am gonna go with Graeme's solution.@ Graeme : Thanks. I am gonna follow this thing. Just that, I will
have to change the refresh rate too as the timer ticks towards zero,
the refresh rate gets higher.

thanks again.

Rgds
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top