Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

client -server in applets

 
ray bond
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello there,
I am trying to understand following applet ,
import java.io.*;
import java.net.*;
import java.awt.event.*;
import java.awt.*;
import java.applet.*;

public class OutPut extends Applet
{

public void init()
{
try{
URL url = new URL("http://server1/c/vippast/hello.txt");
URLConnection urlcon = url.openConnection();
urlcon.setDoOutput(true);

urlcon.setUseCaches(true);
ByteArrayOutputStream bt = new ByteArrayOutputStream(512);
PrintWriter pt = new PrintWriter(bt,true);
String str = new String(URLEncoder.encode("this is output applet ")) ;
pt.print(str);
pt.flush();
urlcon.setRequestProperty("Content-Type" , "application/x-www-form-urlencoded");
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
what should this applet do ? , does it writes string "this is output applet " in hello.txt file on server , what is the purpose of this code and how does printwriter.print(string) , connection.setDoOutput() , works ?
thaks

[This message has been edited by ray bond (edited November 22, 2000).]
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't do anything. They never tie their OutputStream to the connection.
connection.setDoOutput() allows you to write to the connection. The default is to not allow writing.
 
ray bond
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
connection.setDoOutput() allows you to write to the connection
, it means in hello.txt file string "this is output servlet"should be written , but after executing this applet when I check hello.txt file , nothing comes in it , so how it allows to write to the connection ?
thanks for your reply.
 
Sarada Bhasker
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. setDoOutput(true) only means writing to output stream is enabled. To actually write to outputstream you should connect it to urlcon's output stream and then use the command writeBytes.
 
ray bond
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your reply,
but then
printwriter.print(string);
printwriter.flush();
what does this mean , does'nt is says that print to printwriter's outputstream??
thanks
 
Sarada Bhasker
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PrintWriter pt in your code is not connected to connection's outputstream. You should tie it up to connection's o/p stream
like
PrintWriter pt = new PrintWriter
(new OutputStreamWriter
(urlcon.getOutputStream()));
Then it should work.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic