File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Applets and the fly likes Applet - Servlet Communication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Applet - Servlet Communication" Watch "Applet - Servlet Communication" New topic

Applet - Servlet Communication

Sid Scud
Ranch Hand

Joined: Mar 13, 2001
Posts: 32
How can I refresh the data in an appet, when some data is updated in the servlet? I have used the meta tag in the applet and it works. But is there any other way to make it work?
Thanks in advance...
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

forgive my ignorance, but could you elaborate on this
meta tag in the applet and it works
I din't know this could be done! I thought the server can't
make calls to the client running the applet, even when the
server-side servlet is updated. So does the servlet
notify/update the applet codebase/class/jar files on the
server side? Just guessing, Sure it is mentioned somewhere on
the sun web site, but then shamlessly asking...
just curious how does it work?
ps: Sorry for intruding into your post and asking you qstns.
But, its just my curiosity thats' talking....
- satya

Take a Minute, Donate an Hour, Change a Life
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Hi Siddharth:
Btw, welcome to the javaranch forums. Just realised
this is your first post.
Hope you enjoy this place!
- satya
Rahul Rathore
Ranch Hand

Joined: Sep 30, 2000
Posts: 324
I recall have read (in O'Reilly's book I think) that one way to have the servlet update a client continuously is by ensuring that the doGet() (or doPost()) method with which this servlet was called does not return. I think you have to implement an eternal loop in doGet() which will continously check for update. If there is no update then thread will go into wait(). An update will issue notifyAll() so that all threads wake up and send the update to the client and then resume in that eternal loop. But I recall that this method was not found good for some reason.
A better method I think would be for the servlet to open a direct Socket connection with all its client applets (eg. maintain a Vector of Sockets as member variable). The update method would iterate through the sockets and send the update data to each client. RMI is another alternative to sockets.
Sid Scud
Ranch Hand

Joined: Mar 13, 2001
Posts: 32
Thanks Madhav for the warm welcome....
i'm sorry .... what i meant to say is that i used meta tag in the html file in which i have embedded the applet. Sorry again...
hope i made it clear so that i can get some valuable help from u !!!
anuj khanna

Joined: Jan 11, 2001
Posts: 20
hi friend ,
what i could understand from your mail was that u wanna know wether u can do applet-servlet communication without using this meta tag of yours.well
there're three ways to carry out applet servlet communication
raw socket
http socket
RMI--serialized objects
well telling u about http communication
in the applet
make a URL object
URL url=new ("location of the servlet");
URLConnection con=url.openConnection();//open a connection
con.setRequestProperty("content type","application/x-www-urlencoded");
BufferedReader br=new BufferedReader(new IntputStreamReader(con.getInputStream()));//depends on your choice what u wanna use
then read the content from the servlet using readLine()or what ever u wish.
well this is very general but hope it will help u.
in the servlet use
req.getWriter()-to write just like u do in html(req is an object of HttpServletRequest)
hope this will be adequate for u
consult java server programming -wrox publication
java servlet programming--o'reilly
for further knowledge
bye. )
I agree. Here's the link:
subject: Applet - Servlet Communication
It's not a secret anymore!