当前位置: 技术问答>java相关
还是关于applet和servlet通信的问题!高手看过来!
来源: 互联网 发布时间:2015-09-06
本文导语: 现在我可以从servlet中取得对象到applet中,但是想在applet中发送对象到servlet中有问题,请看我的代码: applet中:------------------------------ URL url = new URL("http://localhost:8080/te...
现在我可以从servlet中取得对象到applet中,但是想在applet中发送对象到servlet中有问题,请看我的代码:
applet中:------------------------------
URL url = new URL("http://localhost:8080/testservlet");
URLConnection conn = url.openConnection();
conn.setRequestProperty("Content-type","application/octest-stream");
conn.setDoInput(true);
conn.setDoOutput(true);
conn.connect();
MyBean b1 = new MyBean();
ObjectOutputStream out = new ObjectOutputStream(conn.getOutputStream());
out.writeObject(b1);
out.flush();
out.close();
servlet中================================
ObjectInputStream in = new ObjectInputStream(req.getInputStream());
MyBean b = (MyBean)in.readObject();
in.close();
为何总是执行到applet中的ObjectOutputStream out = new ObjectOutputStream(conn.getOutputStream());时发生IOException????????
applet中:------------------------------
URL url = new URL("http://localhost:8080/testservlet");
URLConnection conn = url.openConnection();
conn.setRequestProperty("Content-type","application/octest-stream");
conn.setDoInput(true);
conn.setDoOutput(true);
conn.connect();
MyBean b1 = new MyBean();
ObjectOutputStream out = new ObjectOutputStream(conn.getOutputStream());
out.writeObject(b1);
out.flush();
out.close();
servlet中================================
ObjectInputStream in = new ObjectInputStream(req.getInputStream());
MyBean b = (MyBean)in.readObject();
in.close();
为何总是执行到applet中的ObjectOutputStream out = new ObjectOutputStream(conn.getOutputStream());时发生IOException????????
|
URLConnection conn = url.openConnection();//建立了连接
//conn.connect();//为什么要再建一次???
ok?
//conn.connect();//为什么要再建一次???
ok?