Dear All,
I am using the following code to call the doPost method of a servlet inside
an Applet but it is not working i.e.
the doPost method of the servlet is not called at all. The applet itself is
called inside the doGet method of the
same servlet which is sending an HTML page inside which the Applet is
embedded. Can anyone help me please.
java.net.URL url = new java.net.URL(codeBase + servlet);
java.net.URLConnection con=url.openConnection();
// Initialize the connection
con.setUseCaches(false);
con.setDoOutput(true);
con.setDoInput(true);
// Data will always be written to a byte array buffer so
// that we can tell the server the length of the data
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
// Create the output stream to be used to write the
// data to our buffer
DataOutputStream out = new DataOutputStream(byteOut);
// Send the proper session id
out.writeUTF(sessionId);
// Send the username and password
out.writeUTF(user);
out.writeUTF(pw);
// Flush the data to the buffer
out.flush();
// Get our buffer to be sent
byte buf[] = byteOut.toByteArray();
// Set the content that we are sending
con.setRequestProperty("Content-type", "application/octet-stream");
// Set the length of the data buffer we are sending
con.setRequestProperty("Content-length","" + buf.length);
// Get the output stream to the server and send our data buffer
DataOutputStream dataOut = new
DataOutputStream(con.getOutputStream());
dataOut.write(buf);
// Flush the output stream and close it
dataOut.flush();
dataOut.close();
Thanks,
Satyan Prakash
Software Engineer
ITIL
___________________________________________________________________________
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