dcsimg
applet send Vector to Servlet
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   John_Zhang
Posted On:   Monday, June 10, 2002 11:42 AM

I'm send a vector from applet to servlet. applet: ObjectOutputStream outputToServlet; String[] thedata={"a","b","c","d"}; Vector vdata = new Vector(); for (int i=0;i vadata.addElement(thedata[i]); } try{ // connect to the servlet String servletLocation = "http://serveur_1:8080/penhr/timecardservlet2"; URL tServlet = new URL( servletLocation ); URLConnection servletConnection = tServlet.openConnection(); // inform the connection that we will send output and accept input servletConnection.setDoInput(true); servletConnection.setDoOutput(true);    More>>
			
I'm send a vector from applet to servlet.
applet:
ObjectOutputStream outputToServlet;

String[]

thedata={"a","b","c","d"};


Vector vdata = new Vector();
for (int i=0;i
vadata.addElement(thedata[i]);
}


try{


// connect to the servlet
String servletLocation = "http://serveur_1:8080/penhr/timecardservlet2";
URL tServlet = new URL( servletLocation );
URLConnection servletConnection = tServlet.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");

outputToServlet = new
ObjectOutputStream(servletConnection.getOutputStream());
outputToServlet.writeObject(vdata);
outputToServlet.flush();
outputToServlet.close();
}catch(Exception e){System.out.print("sendtoServlet"+e);}

servlet:

public void service(HttpServletRequest request,HttpServletResponse response)
throws IOException {

ObjectInputStream inputFromApplet;
PrintWriter out=response.getWriter();
Vector rows=new Vector();


{
inputFromApplet = new ObjectInputStream(request.getInputStream());
rows = (Vector)inputFromApplet.readObject();
inputFromApplet.close(); }
catch (Exception e) {}
System.out.println("receieve.."+rows);


System.out.println("end--receieve");
out.print(rows);
}//service

but the servlet seems didn't get data.
can you check what's wrong?

   <<Less
About | Sitemap | Contact