有关Applet和Servlet通讯的怪事。

hurt75 2001-11-30 10:46:56
当Applet发字符串给Servlet的时候,我flush 了close了,但我再按一次Applet的发送的话,为什么Servlet收到的确实是二个串加在一起呢?比如我发送了“abcde”,当再按一次Applet发送的时候却收到了"abcdeabcde"是二串想加,Servlet的out每次也close了,就是不行,反正是按一次串就再加一次,奇怪,请问这是怎么回事?
...全文
158 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
javamap 2001-12-01
  • 打赏
  • 举报
回复
I believe both Applet and Servlet works correctly. The problem is in your code after Servlet receiving.
xpxxp 2001-12-01
  • 打赏
  • 举报
回复
管道流中数据不清除,请你改用SOCKET通信,如果你坚持做,你就只能让APPLET发,SERVLET收。管道的连接是单向的,如果你用这个连接发数据,你自己可以用输入流收下来。而SOCKET则不是他的连接是双向的。
dracowoo 2001-12-01
  • 打赏
  • 举报
回复
请讲清楚一些。。我还是不清楚。我的问题是这样的。当网页关掉的是时候就没有这个问题
。但是如果网页不关闭。譬如说在网页上有一个按钮。我第一次点击的时候。工作正常。如果我
点击两次以上的话。我在servlet的request接收的数据总是两个数据串ping在一起的。就是前一次送的串也存在。
到底是applet里设置联接的时候有什么问题吗?我的applet里面的方法代码如下
private void sendXMLStr() {

try {

URL codeBase = getCodeBase();

URL url =
new URL(
"http://"
+ codeBase.getHost()
+ ":"
+ codeBase.getPort()
+ "/servlet/com.cs.eximbills.RegisterServlet");

String xmlStr =
URLEncoder.encode("xmlStr") + "=" + URLEncoder.encode(XMLStr.toString());

URLConnection uc = url.openConnection();
uc.setDoOutput(true);
uc.setDoInput(true);
uc.setUseCaches(false);
uc.setRequestProperty("Content-type", "application/x-www-form-urlencoded");

//------------begin write the xml str to the outputStream----------------//
/*try {
PrintWriter out=PrintWriter(uc.getOutputStream());
//out.print(xmlStr+"="+URLEncoder.encode(XMLStr.toString()));
} catch (Exception e) {
System.out.println(e.toString());
}*/
try {
DataOutputStream dos = new DataOutputStream(uc.getOutputStream());
dos.writeBytes(xmlStr);
//dos.writeChars(xmlStr);
dos.flush();
dos.close();
} catch (Exception e) {
System.out.println("can't write to OutputStream");
}

//------------end write the xml str to the outputStream-------------------//

InputStreamReader in = new InputStreamReader(uc.getInputStream());
int chr = in.read();
while (chr != -1) {
//taResults.append(String.valueOf((char) chr));
chr = in.read();
}
in.close();

} catch (MalformedURLException e) {
System.out.println(e.toString());
} catch (IOException e) {
System.out.println(e.toString());
}

}我在servlet接收xmlStr这个值。谢谢

81,122

社区成员

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

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