Hi.
> 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");
1)You can to do overwise :))
servlet = new URL(codeBase, "/FileReadServlet");
But it is not decision you problem :)))
> >>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");
2)Try to do it
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded,
boundary=<separator>");
<separator> - Look http://andrew2.andrew.cmu.edu/rfc/rfc1867.html
> >> //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.
Regards,
Mank.
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html