String command="ping 127.0.0.1";
Process process = Runtime.getRuntime().exec(command);
BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = bufferedreader.readLine();
for(;line != null;) {
String nextLine = bufferedreader.readLine();
//在此处理获得的ping反馈信息,比如下边的打印
System.out.println(line);
line = nextLine;
}
bufferedreader.close();简单的例子,不过我想足够了吧?
Process process = Runtime.getRuntime().exec(command);
BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = bufferedreader.readLine();
for(;line != null;) {
String nextLine = bufferedreader.readLine();
//在此处理获得的ping反馈信息,比如下边的打印
System.out.println(line);
line = nextLine;
}
bufferedreader.close();简单的例子,不过我想足够了吧?
解决方案 »
- jsp中调用js方法传参问题
- 服务器上只开一各端口接收socket消息,客户端怎么通过IE访问页面?
- 那种查询方式的效率更高
- 我用的是resin服务器运行jsp,但总是找不到com.*;
- 关于注销问题
- javaMail包
- (jsp)日期格式判断(比如20070520)且结束日期大于开始日期!
- linux(Red Hat 9.0)下用组建JspSmartUpload上传文件中文显示为乱码,见到的方法都式了,但不起作用,高手求助呀!!
- 聊天室中的显示在线人数和显示登陆用户姓名?
- JSTL循环输出的问题
- jsp是怎么了解mysql的?能给个例子吗?
- 下载了sqlserver的jdbc驱动程序后怎么在weblogic里面配置
如果是的话,可以在ResultSet.executeQuery();调用前后截取系统时间并进行相关处理就是了阿。
不过我没做过相关的,意见仅供参考
第二个问题解决就是你所说的那样啊!第一个问题解决解决如下:
<%@ page import="java.io.*" %><%
Runtime runtime = Runtime.getRuntime();
Process process =null;
String line=null;
InputStream is =null;
InputStreamReader isr=null;
BufferedReader br =null;
String ip="你要ping的ip";
//自行修改上面的ip位址
try
{
process =runtime.exec("ping "+ip);
is = process.getInputStream();
isr=new InputStreamReader(is);
br =new BufferedReader(isr);
out.println("<pre>");
while( (line = br.readLine()) != null )
{
out.println(line);
out.flush();
}
out.println("</pre>");
is.close();
isr.close();
br.close();
}
catch(IOException e )
{
out.println(e);
runtime.exit(1);
}
%>
Reply from 202.112.0.36: bytes=32 time=47ms TTL=246Reply from 202.112.0.36: bytes=32 time=78ms TTL=246Reply from 202.112.0.36: bytes=32 time=141ms TTL=246Reply from 202.112.0.36: bytes=32 time=47ms TTL=246Ping statistics for 202.112.0.36: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),Approximate round trip times in milli-seconds: Minimum = 47ms, Maximum = 141ms, Average = 78ms
Reply from 202.112.0.36: bytes=32 time=78ms TTL=246
信息,然后可以用String的各种方法来获得'time=78ms'中的78ms这个信息,如果这就是你想要的所谓“一次ping时间”的话
while( (line = br.readLine()) != null )
{
if(line.lastIndexOf("Reply")!=-1){
String time;
time=line.substring(line.lastIndexOf("time")+5,line.lastIndexOf("TTL")/*若要仅得到数值,此处加上 -3 */);
out.println(time);
out.flush();
return;
}
C:\bea\user_projects\mydomain\myserver\.wlnotdelete\DefaultWebApp_DefaultWebApp_5982438\jsp_servlet\_main\__u_search.java:128: 'catch' without 'try'
probably occurred due to an error in /main/U_search.jsp line 38:
catch(IOException e )C:\bea\user_projects\mydomain\myserver\.wlnotdelete\DefaultWebApp_DefaultWebApp_5982438\jsp_servlet\_main\__u_search.java:88: 'try' without 'catch' or 'finally'
(No more information available, probably caused by another error)C:\bea\user_projects\mydomain\myserver\.wlnotdelete\DefaultWebApp_DefaultWebApp_5982438\jsp_servlet\_main\__u_search.java:157: '}' expected
(No more information available, probably caused by another error)
}