ObjectOutputStream和ObjectInputStream的问题!
public static Object dispatch(Object dispatchObject)
{
String appletURLParameter = "http://192.168.1.1:8080/TestApplet/ServletDispatcher";
Object returnObject = null;
try
{
URL url = new URL(appletURLParameter);
URLConnection connection = url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
//本次连接不用Cache
connection.setUseCaches(false);
//下次连接不用Cache
connection.setDefaultUseCaches(false);
connection.setRequestProperty("Content-Type", "application/octet-stream");
ObjectOutputStream oos = new ObjectOutputStream(connection.getOutputStream());
oos.writeObject(dispatchObject);
oos.flush();
oos.close();
ObjectInputStream ois = new ObjectInputStream(connection.getInputStream());
returnObject = ois.readObject();
}
catch (ClassNotFoundException ex)
{
ex.printStackTrace();
}
catch (MalformedURLException ex)
{
ex.printStackTrace();
}
catch (IOException ex)
{
ex.printStackTrace();
}
return returnObject;
}
我的做法是把一个序列化的对象传递给一个SERVLET,它的名字叫ServletDispatcher,然后在SERVLET里做一系列操作,返回对象给applet,但
ObjectInputStream ois = new ObjectInputStream(connection.getInputStream());
returnObject = ois.readObject();
connection.getInputStream()为什么为unknow resource呢?
ObjectOutputStream oos = new ObjectOutputStream(connection.getOutputStream());
oos.writeObject(dispatchObject);
oos.flush();
oos.close();
把上述四行代码注掉就正常了?
问题点数:20、回复次数:7Top
1 楼ChDw(米)回复于 2006-03-14 15:07:11 得分 0
你看看不要调用oos.close看看,这个时候不太应该关闭这个流吧Top
2 楼rhj_2001(浩)回复于 2006-03-14 15:16:03 得分 0
是不是代码写的有问题?oos.close注释掉了,还是有问题。
Top
3 楼rhj_2001(浩)回复于 2006-03-14 15:26:29 得分 0
有人回答么?Top
4 楼ChDw(米)回复于 2006-03-14 15:51:18 得分 20
应该是你的服务器代码存在问题吧,我试过是可以的
URL url = new URL(appletURLParameter);
URLConnection connection = url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
//本次连接不用Cache
connection.setUseCaches(false);
//下次连接不用Cache
connection.setDefaultUseCaches(false);
connection.setRequestProperty("Content-Type", "application/octet-stream");
ObjectOutputStream oos = new ObjectOutputStream(connection.getOutputStream());
oos.writeObject(new Integer(3));
oos.flush();
ObjectInputStream ois = new ObjectInputStream(connection.getInputStream());
System.out.println(ois.readObject());
--------------------------
ObjectInputStream ois = new ObjectInputStream(request.getInputStream());
System.out.println(ois.readObject());
ObjectOutputStream oos = new ObjectOutputStream(response.getOutputStream());
oos.writeObject(new Integer(333));
oos.flush();
------------
服务器可以打印3,客户端会打印333Top
5 楼rhj_2001(浩)回复于 2006-03-14 16:09:13 得分 0
我在服务端DEBUG了,断点根本不能到达那里。错误是从客户端那里抛出来的。
ObjectOutputStream oos = new ObjectOutputStream(connection.getOutputStream());
只要这段代码存在,就有错误;这段代码注释掉,可以到达服务端的SERVLET。Top
6 楼rhj_2001(浩)回复于 2006-03-14 16:28:01 得分 0
跟tomcat版本有关么?Top
7 楼rhj_2001(浩)回复于 2006-03-14 20:37:18 得分 0
有人碰到过类似问题么?Top
相关问题
- 各位老兄好,通过ObjectoutputStream ,ObjectINputStream 如何读写数据
- ObjectInputStream读数据的问题??
- 谁能告诉我如何使用ObjectInputStream。
- 关于ObjectInputStream类使用的问题
- =====请教一个有关ObjectInputStream的问题=====
- ObjectInputStream传输对象的问题
- 请教ObjectOutputStream输出乱码问题
- 倾家荡产:求解ObjectInputStream 的错误
- 如何用ObjectOutputStream,ByteArrayOutputStream向一个RandomAccessFile文件中写读数据
- ObjectOutputStream问题,怎样把一个对象存成文件.




