使用ajax获取实时ping结果
我正在尝试创建一个可以实时显示 ping 命令结果的 Web 应用程序。我在后台使用JSP。我实际上得到了正确的结果。但问题是,结果不能实时显示。应用程序处理 ping 命令并立即转储结果。我需要的是,应用程序必须在获得一行结果时逐行显示结果。
这是我的代码
String ip = request.getParameter("ipaddress");
String pingCmd = "ping -c 3 " + ip;
Runtime runtime = Runtime.getRuntime();
Process p = runtime.exec(pingCmd);
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
{
out.println(inputLine + "<br />");
}
in.close();
我需要对此代码进行什么更改。
问候
苏尼尔·库马尔 BM
I'm trying to create a web application which can display the results of a ping command real-time. I'm using JSP in the backend. I'm actually getting the result correctly. But the problem is, the result is not displayed in real-time. The application processes the ping command and dumps the result all at once. What I need is that, the application has to display the result line after line as and when a line of result is obtained.
Here is my code
String ip = request.getParameter("ipaddress");
String pingCmd = "ping -c 3 " + ip;
Runtime runtime = Runtime.getRuntime();
Process p = runtime.exec(pingCmd);
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
{
out.println(inputLine + "<br />");
}
in.close();
What is the change I need to make in this code.
Regards
Sunil Kumar B M
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 comet servlet 来完成此操作。对于 Tomcat 6: http://tomcat.apache.org/tomcat-6.0-doc /aio.html
You can do this with a comet servlet. For tomcat 6: http://tomcat.apache.org/tomcat-6.0-doc/aio.html