读书人

applet与servlet通信有关问题

发布时间: 2012-01-09 21:05:42 作者: rapoo

applet与servlet通信问题.
我建了一个非常简单的applet,怎么就和servlet通信不了那.servlet中接不到值.哪位帮看看

applet::

public void init() {
JButton jb=new JButton( "OK ");
this.add(jb);
try {
URL url = new URL( "http://localhost:8080/demo/servlet/myServlet?send_param=hello ");
URLConnection connect = url.openConnection();
// 下次连接不用Cache
connect.setDefaultUseCaches(false);
// 这次连接也不用Cache
connect.setUseCaches(false);
// 打开流用于读数据
connect.setDoInput(true);
// 不能用于写数据
connect.setDoOutput(false);

// 服务器与客户的真正连接
connect.connect();
}catch (Exception e) {
e.printStackTrace();
}

// Put your code here
}


[解决办法]
这样的设置下,必须读数据,才能使得connect对象真正向url发出请求。

读书人网 >Java Web开发

热点推荐