I have tried to invoke sendRedirect() in doPost method when the applet's
button is pushed, but it did not work. Here is the code:
Please help me...
-------this is applet acctionPerformed code------------
void jButton1_actionPerformed(ActionEvent e) {
System.out.println("Sending data...\n");
try {
URL url = new URL("http://localhost:8080/servlet/Servlet_1");
URLConnection con = url.openConnection();
con.setUseCaches(false);
con.setDoOutput(true);
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(byteOut);
out.writeUTF(txtField.getText());
out.flush();
byte[] buf = byteOut.toByteArray();
con.setRequestProperty("Content-type", "application/octet-stream");
con.setRequestProperty("Content-length", "" + buf.length );
DataOutputStream dataOut = new DataOutputStream(con.getOutputStream());
dataOut.write(buf);
dataOut.flush();
dataOut.close();
}catch(Exception ex) { ex.printStackTrace(); }
System.out.println("Data was sent...");
}
------and this is the servlet doPost code----------
public void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = new PrintWriter (response.getOutputStream());
out.println("<html>");
out.println("<head><title>Servlet1</title></head>");
out.println("<body>");
out.println("The servlet has received a POST. This is the reply.");
out.println("</body></html>");
DataInputStream in = new DataInputStream(request.getInputStream());
String s = in.readUTF();
in.close();
out.println("<p>s: " + s);
response.sendRedirect("http://deniz:8080/servlet/Servlet_2");
out.flush();
out.close();
}
___________________________________________________________________________
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