Applet向Servlet传递二进制(Vector)数据失败 ,求救阿!快来阿!
那位大哥帮我看一下下面的代码,我的applet可以读出servlet的冬冬,可就是不能向applet写数据,气死人了!
当我调用applet的 writeToExcelServlet() 方法后,连接可以正常建立,可servlet好像根本没有收到Post请求一样,没有任何反映,甚至联我的
System.out.println("Call doPost and begin receiving the data from applet. "); 也没有在控制台输出, 艾.............
applet里的代码:
public void writeToExcelServlet() {
try {
ObjectOutputStream outputToServlet = null;
Vector appletData = (Vector) dataModel.getDataVector().clone();
appletData.insertElementAt(this.columnIdentifiers, 0);
// connect to the servlet
URL excelServlet = new URL(webPath+ "/qbean/servlet/smic.QBeanExcelServlet");
URLConnection servletConnection = excelServlet.openConnection();
showStatus("Connected to servlet successfully!");
// 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
outputToServlet = new ObjectOutputStream(servletConnection.getOutputStream());
// Put dataModule to the servlet.
outputToServlet = new ObjectOutputStream(servletConnection.getOutputStream());
outputToServlet.writeObject(appletData);
outputToServlet.flush();
outputToServlet.close();
showStatus("Send data to servlet finished!");
} catch (Exception e) {
showStatus("Write table content vector to servlet failed ." + e);
}
}
servlet里的接受代码:
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
System.out.println("Call doPost and begin receiving the data from applet. ");
Vector data=null;
ObjectInputStream inputFromApplet=new ObjectInputStream(req.getInputStream());
data=(Vector)inputFromApplet.readObject();
// some process...........
ServletOutputStream stream = res.getOutputStream();
res.setContentType("application/vnd.ms-excel");
wb.write(stream);
stream.flush();
stream.close();
} else{
System.out.println("Data is null .");
}
}