使用ajax获取实时ping结果

发布于 2025-01-02 05:41:54 字数 592 浏览 2 评论 0原文

我正在尝试创建一个可以实时显示 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天涯离梦残月幽梦 2025-01-09 05:41:54

您可以使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文