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
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
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.