You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Thomas Bierhance <Bi...@orbital-computer.de> on 2000/09/16 21:34:09 UTC
Entity-Body missing using POST from Applet to Servlet
Hello!
I have a applet-servlet combination here that works well using
the webserver that comes with my IDE (it is sun's forte for java,
which uses the "sun java web server"(?) I think).
Today I tried to get the two working using the tomcat engine, but when
my servlet tries to read the entity-body from the applet's POST the
stream contains nothing.
I am sorry for code that follows, but I think it is necessary - I'll
keep it short and easy to understand. The applet talks...
String msg="Hello Servlet!";
// URL- and socket-stuff
java.net.URL url = new java.net.URL("http://myhost:8080/myDir/myServlet?mySessionID=123");
String host = url.getHost(); int port = url.getPort(); String file = url.getFile();
Socket sockAcceptor = new Socket(host, port, true);
// Getting Output-Stream to servlet
DataOutputStream outStream = new DataOutputStream(new BufferedOutputStream(sockAcceptor.getOutputStream(), 1024));
// writing HTTP-header
outStream.writeBytes("POST " + file + " HTTP/1.0\r\n");
outStream.writeBytes("Host: " + host + "\r\n");
outStream.writeBytes("Content-Type: " + "application/x-myApplet" + "\r\n");
outStream.writeBytes("Content-Length: " + msg.length() + "\r\n");
outStream.writeBytes("\r\n");
// writing body
outStream.writeUTF(msg);
outStream.flush(); [...]
Now the following servlet-code used to get the msg-String without any
problems...
// handle the applet-request
public void service(HttpServletRequest req) {
// Get a stream for the request's body
DataInputStream inStream = new DataInputStream(req.getInputStream());
// read the message
String msg = inStream.readUTF();
Now, what is happening here? It works using the sun server...
Thanks for your time and best regards,
Tom mailto:Bierhance@orbital-computer.de