• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to communicate Applet to Servet

 
Vishnu Murthy
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
can u please tell me how to communicate with applet to servlet.
for ex. say want to display the current stock market details on to the applet.
or i want to display the question from the database to the Applet.
thanks
vishnu
 
Tanveer Rameez
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
I am in a hurry, so I won't be able to explain it to you right now. But I suggest you go through "Java Servlet prograaming" O'Reilly publications, specially the applet servlet communication chapter
 
jos xavier
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vishnu murthy:
Hi Friends,
can u please tell me how to communicate with applet to servlet.
for ex. say want to display the current stock market details on to the applet.
or i want to display the question from the database to the Applet.
thanks
vishnu

Hi Vishnu,
You can connect to the servlet on click of the button using the actionPerformed(ActionEvent ae)
URL url = new URL("<servletName>");
URLCOnnection urlCon = url.openConnectoin();
ObjectInputStream ois = new ObjectInputStream(urlCon.getInputStream());
you can get the object by doing the necessary casting ad getting the data .
For this you can create a class which stores the data. The data is stored in this class by the servlet anf when a call is made to the servlet, this class is sent from the ObjectOutputStream of the servlet. The applet can read data from this class by casting it.
try it and let me know
bye
joseph
 
Rahul Rathore
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jos,
I think that the above solution allows only one way communication - from servelet (or any resource) to the applet. What if the applet must submit parameters to the servlet, and then receive the response from the servlet, depending on the parameters. Should we append the GET parameters to the String url and then do URL url=new URL(url)? What about the POST method- here the request body is separate from the URL?
I think the applet must open a low level Socket connection (new Socket(host,port) with the web server and then send and receive through that socket. This means that the applet will need to write through the socket using the http protocols i.e. it will have to write properly formatted strings of GET or POST request.
I know these things are available in books like O'Reilly's, Core Java etc. I am hoping Vishnu will do the R & D and let us know the WHOLE truth.
 
anuj khanna
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
i think req.getParameter()
will help you.(req is an object of HttpServletRequest)
 
Justin Chu
Ranch Hand
Posts: 209
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think this is possible for the servlet to push data to the applet because the applet does not listen to a port on your computer.

Constant polling will be a method to do that.
[ December 09, 2004: Message edited by: Chu Tan ]
 
Gauri Deshmukh
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
Here is a link for communicating from servlet-applet or vice versa.
Hope it helps.
http://www.artima.com/forums/flat.jsp?forum=1&thread=71991
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic