Hi,
I am trying to transfer data from client machine to server using applet-servlet communication. But it seems that my applet cannot open an Output stream with the servlet. However, I can send data from servlet to applet. Here is the concerned part of code....
 
MyApplet.java

>>URL codebase = this.getCodeBase();
>>String host = codebase.getHost();
>>String protocol = codebase.getProtocol();
>>int port = codebase.getPort();
>>// Build the URL for the servlet web server
>>URL webBase = new URL(protocol + "://" + host + ":" + port);
>>servlet = new URL(webBase, "/FileReadServlet");
>>label.setText(protocol + "://" + host + ":" + port+"/MyServlet");   // no need to put in servlets directory
>>URLConnection con = servlet.openConnection();
>>con.setDoOutput(true);
>>con.setDoInput(true);
>>con.setUseCaches(false);
>>con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
>>  //con.connect();
>>OutputStream out = con.getOutputStream();
>>//
>>ObjectOutputStream os = new ObjectOutputStream(out);
>>os.writeObject(new String("Hello"));

MyServlet.java

>>ObjectInputStream ds = new ObjectInputStream( req.getInputStream());
>>System.out.println("Openend stream with the client"+ req.getRemoteHost());
>>      try{
>>      String st = (String)ds.readObject();
>>      System.out.println(st);
>>      }
>>      catch( Exception e) {System.out.println("Exception in conversion");}

Well, the whole system seems to be doing nothing whenever I try to open the outputstream from applet to servlet.

I'll highly appreciate if you can suggest some solution,

Thanks in advance,

Rashid.

 

 

 

 

 

 

 

 

Reply via email to