This is one of the most frequently used techniques. From your applet create a URL connection the Servlet and send the data using DataOutputStream. Next in the Service method of Servlet, using PrintWriter, create a new File. On the other end Applet will be waiting for response from Servlet, using DataInputStream. Pass the newly created filename to the Applet. Next From applet call ShowDocument() method with new URL.
Here is some sample code,
URL ticketservlet = new URL( "http://jcom.com/servlet/Ticketservlet ");
URLConnection servletConnection = ticketservlet.openConnection();
// inform the connection that we will send output and accept input
servletConnection.setDoInput(true);
servletConnection.setDoOutput(true);
// Don't use a cached version of URL connection.
servletConnection.setUseCaches (false);
servletConnection.setDefaultUseCaches (false);
// Specify the content type that we will send binary data
servletConnection.setRequestProperty ("Content-Type", "application/octet-stream");
// send the student object to the servlet using serialization
ObjectOutputStream ticketOutputToServlet = new ObjectOutputStream(servletConnection.getOutputStream());
// serialize the object , and sending it to servlet , ticketData should implement Serializable interface.
ticketOutputToServlet .writeObject(ticketData);
ticketOutputToServlet .flush();
ticketOutputToServlet .close();
//reading back data from servlet
ObjectInputStream inputFromServlet = new ObjectInputStream(servletConnection.getInputStream());
Vector resultantData = (Vector) inputFromServlet.readObject();
String filename = (String) resultantData.elementAt(0)
//Showing the newly created page from Applet
getAppletContext().showDocument(new URL("http://www.jcom.com/profiles/" + filename));
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment