Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2008

Tip: Looking for answers? Try searching our database.

Display Updated/changed value(from cache) in JSP

Thread view: 
Buddha - 30 Jan 2008 06:32 GMT
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,
GArlington - 30 Jan 2008 12:10 GMT
> Dear all,
>
[quoted text clipped - 24 lines]
> 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,
gwoodhouse@gmail.com - 30 Jan 2008 15:34 GMT
> 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
Buddha - 31 Jan 2008 05:12 GMT
On Jan 30, 8:34 pm, "gwoodho...@gmail.com" <gwoodho...@gmail.com>
wrote:
> > There is a timer running.
>
[quoted text clipped - 12 lines]
>
> 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
Lew - 31 Jan 2008 14:50 GMT
> On Jan 30, 8:34 pm, "gwoodho...@gmail.com" <gwoodho...@gmail.com>
> wrote:
[quoted text clipped - 24 lines]
> 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.

Signature

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

Daniel Pitts - 01 Feb 2008 01:52 GMT
> On Jan 30, 8:34 pm, "gwoodho...@gmail.com" <gwoodho...@gmail.com>
> wrote:
[quoted text clipped - 41 lines]
>
> 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).
Buddha - 01 Feb 2008 08:52 GMT
> 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
@ 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.