hi everyone !! i have made a program to communicate from a applet to a servlet applet code ------------ import java.awt.event.*; import java.awt.*; import java.applet.*; import java.net.*; import java.io.*; public class client15 extends Applet implements ActionListener {String a="yvooo"; TextField t1; Button b1; public void init() { t1=new TextField(10); b1=new Button("Send"); add(t1); add(b1); t1.addActionListener(this); b1.addActionListener(this); } public void actionPerformed(ActionEvent ae) {String s=t1.getText(); try{ URL xx=new URL("http://parminder:9000/cool/book5"); a="helloasd"; repaint(); URLConnection c = xx.openConnection(); c.setDoInput(true); c.setDoOutput(true); c.setUseCaches (false); c.setDefaultUseCaches (false); c.setRequestProperty ("Content-Type", "application/octet-stream"); DataOutputStream d; d = new DataOutputStream(c.getOutputStream()); d.writeBytes(s); d.flush(); d.close(); /*DataInputStream d1 = new DataInputStream(c.getInputStream()); a=d1.readLine(); repaint(); d1.close();*/ }catch(Exception e) {a=("fdf"+e); repaint();}} public void paint(Graphics g) {g.drawString(a,10,50); }} this code is working fine.i am getting the connection to the servlet as :helloasd" is printed after i click the "send" button.
(I am invoking the applet from a html file from the Browser.) now when i run this servlet from browser window it gives a READ TIMED OUT exception.even if i use doPost or service method problem remains the same.
now if I remove the comment tag from the applet and include that code as a part of the applet program(which takes the InputStream of the servlet and print the input),it works fine. it means if i input "hello" in the textfield .press the "send" button then this "hello" is written in the applet(via servlet InputStream) now this works only if I use "doPost" method in the servlet. if i want to run the servlet now and see the data send from the applet it works also.(But it does not work on clicking the Refresh button in the browser.405 error). please tell me the solution so that i will be able to see the message send from the applet to the servlet when i run the servlet excluding the code in the comment area in the applet. it is a bit confusing but if you try the code ,i think everything will be clear.
thanks asheet
maha anna
Ranch Hand
Joined: Jan 31, 2000
Posts: 1467
posted
0
Please try this link. I haven't done much on applet-servlet communication. This link seems to give some usefule info. http://pages.about.com/kmukhar/ regds maha anna