Plz discuss the followed issue about Servlet and HttpURL.........
Under tomcat platform, I wrote a servlet ,and it's functionality is get data stream from client and display in the console window.:
publicclass UploadFileServletextends HttpServlet
{
protectedvoid doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
{
InputStream inf=request.getInputStream();
int len=0;
byte b[]=newbyte[20];
while((len=inf.read(b))>0)
{
String str=new String(b,0,len);
System.out.println(str);
}
}
}
And the followed is the client..
URL url=new URL("http://localhost:8080/Test");//这个url可以访问上面的Servlet
HttpURLConnection httpConnection=(HttpURLConnection) url.openConnection();
httpConnection.setRequestMethod("POST");
httpConnection.setDoOutput(true);
OutputStreamWriter osw=new OutputStreamWriter(httpConnection.getOutputStream());
osw.write("A is Writing Something");
osw.flush();
System.in.read();//wait for input for a stop.....
osw.write("\n Are you OK?");
osw.flush();
osw.close();
System.out.println(httpConnection.getContentType());
The server should display "A is Writing Something "...then wait for the client to input , then display "\nAre you OK? "...But here, it doesn't work !
Why ? and how to implement such a functionality ?
Thanks for your reading...
Message was edited by:
Seaughter

