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(); 把上述四行代码注掉就正常了?
{
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(); 把上述四行代码注掉就正常了?
解决方案 »
- StringBuffer和StringBuilder有什么区别啊
- 关于父类与子类的一点深入思考
- 我想用javascript读取Session的值(两个页面都是服务器端,赋值的页面使用VB)
- 关于得到一个范围内的随机数
- 一道内部类的面试题
- 关于组件焦点设置的问题!!!
- g.drawString()多行显示问题?
- 系统找不到指定的文件,怎么办啊???
- 关于JTable中的图片显示问题!哪位帮帮忙!
- 怎样弹出一个对话框,我只知道在delphi里用showmessage('hello');,不知在java里怎么写?
- 高分求救 我在UNIX系统上 读取文件中文乱码问题
- 各位大哥大姐,小弟刚刚学了点数据结构,老板明天就叫我写个模块 我快不行了 大家帮帮忙把
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,客户端会打印333