使用applet文件上传,怎么样都接收不到东西

skyxj 2004-08-20 05:21:52
客户端程序是applet,服务段程序是servlet,功能为进行文件上传,按照现在的byte[]类型发送发送文件时,即outputToServlet.writeObject(byteFile),客户端收不到任何东西;如果采用outputToServlet.writeObject("ssssssss")发送String类型,服务器端能正常接收消息,不知道如何使用applet上传文件?
程序的代码如下

客户端程序:
String queryString = "/filedata/AppletUploadServlet?func=doUpload";
URL url = getCodeBase();
URLConnection connect;
try {
connect = (new URL(url, queryString)).openConnection();
connect.setDoInput(true);
connect.setDoOutput(true);
connect.setDefaultUseCaches(false);
connect.setUseCaches(false);
connect.setRequestProperty("Content-Type", "application/octet-stream");
ObjectOutputStream outputToServlet = new ObjectOutputStream(connect.getOutputStream());

byte [] byteFile = new byte[alFile.size()];
try {
fis = new FileInputStream((String)alFile.get(i));
dis = new DataInputStream(fis);
byteFile[i] = dis.readByte();
} catch(IOException e) {
}

outputToServlet.writeObject(byteFile);
outputToServlet.flush();
outputToServlet.close();
connect.getInputStream();

} catchmedURLException ue) {
} catchption ioe) {
}

服务段程序:
ObjectInputStream in = new ObjectInputStream(req.getInputStream());
int totalBytes = req.getContentLength();
byte [] binArray = new byte[totalBytes + 2];
int readBytes = 0;
while(in.read(binArray) != -1) {
}
DataOutputStream dos = new DataOutputStream(
new BufferedOutputStream(
new FileOutputStream("c:\\aaa")));
dos.write(binArray);
dos.flush();
dos.close();
in.close();
...全文
151 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhonghua2003 2004-10-09
  • 打赏
  • 举报
回复
为了生活,我们努力工作!帮你顶~_~!!
linjie4387 2004-10-09
  • 打赏
  • 举报
回复
你的applet在访问本地资源时候要做数字签名,否则要抛异常。
发送字符串时候,没有读取客户端文件,所以不会抛异常,当然可以收到“ssssssss”
hiking 2004-08-20
  • 打赏
  • 举报
回复
why use ObjectOutputStream
why not BufferedOutputStream or some one else?
alaal 2004-08-20
  • 打赏
  • 举报
回复
MARK
homeland520 2004-08-20
  • 打赏
  • 举报
回复
帮你up一下

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧