Display Updated/changed value(from cache) in JSP

  • Follow


Dear all,I did post this on the sun forum with out too much help. I am assumingI shall be lucky enough to get some here.Since I am clueless on how I wish to do it, I do not really haveanything that I have done.This is part of my problemWhat I am doing is : Displaying the value (price of an item) from thedatabase 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 Ineed to do it : to display this updated price (from the cache) in allbrowsers that are currently "seeing" this JSP, without having torefresh the jsp, i.e.I have dabbled with ajax, however I am stuck at : the Jsp can make anasync. call to the servlet, but how do I make the servlet send thechanged 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 wouldaccess. they could change values (prices, amounts they would enter asa bid). If a user A enters an amount then that should be displayed toother users logged in too. Users B,C and D should be able to see thechanged amount, which means B,C and D('s browsers) should beautomatically updated. They wouldnt be making any requests to theserver.What ways could I explore to achieve this behaviour ?I would appreciate if some one could point me to a direction.Rgds,
0
Reply Buddha 1/30/2008 6:32:20 AM

On Jan 30, 6:32 am, Buddha <happybudd...@gmail.com> wrote:
> 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.

> What ways could I explore to achieve this behaviour ?
>
> I would appreciate if some one could point me to a direction.
>
> Rgds,

0
Reply garlington (99) 1/30/2008 12:10:39 PM


> 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 aservlet every few seconds/minutes (depending on your capacity/serverload). In this way the response could give the value of the field youneed.Ive done something similar in the past, but at a previous company so ican't copy paste code im afraid. I managed it with the references atw3schools. Great site that.Hope that helps,Graeme
0
Reply gwoodhouse 1/30/2008 3:34:08 PM

On Jan 30, 8:34=A0pm, "gwoodho...@gmail.com" <gwoodho...@gmail.com>
wrote:
> > 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


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

0
Reply happybuddha1 (5) 1/31/2008 5:12:40 AM

Buddha wrote:
> On Jan 30, 8:34 pm, "gwoodho...@gmail.com" <gwoodho...@gmail.com>
> wrote:
>>> 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
> 
> 
> 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.

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 );
}
0
Reply lew (2143) 1/31/2008 2:50:19 PM

On Jan 30, 9:12 pm, Buddha <happybudd...@gmail.com> wrote:
> On Jan 30, 8:34 pm, "gwoodho...@gmail.com" <gwoodho...@gmail.com>
> wrote:
>
>
>
> > > 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
>
> 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

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).
0
Reply googlegroupie (586) 2/1/2008 1:52:30 AM

> 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 workfor youI 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@ Graeme : Thanks. I am gonna follow this thing. Just that, I willhave to change the refresh rate too as the timer ticks towards zero,the refresh rate gets higher.thanks again.Rgds
0
Reply Buddha 2/1/2008 8:52:09 AM

6 Replies
129 Views

(page loaded in 0.114 seconds)

Similiar Articles:













7/16/2012 10:28:10 AM


Reply: