How can you push data from an Applet to Servlet

Showing Answers 1 - 1 of 1 Answers

kotireddy

  • Mar 25th, 2007
 

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));

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions