• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet - Servlet Communication

 
Sid Scud
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
-sid
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

forgive my ignorance, but could you elaborate on this
please.....
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?
Thanks.
ps: Sorry for intruding into your post and asking you qstns.
But, its just my curiosity thats' talking....
- satya
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Siddharth:
Btw, welcome to the javaranch forums. Just realised
this is your first post.
Hope you enjoy this place!
regds.
- satya
 
Rahul Rathore
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !!!
-sid
 
anuj khanna
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.setDoOutput(true);
con.setDoIntput(true);
con.setUseCaches(false);
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
or
java servlet programming--o'reilly
for further knowledge
bye. )
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic