把执行dos命令的代码放到一个class里去,jsp去调用,得到ping的结果

解决方案 »

  1.   

    我使用的是javabean,我在bean的类中建立了一个循环检测的函数,
    然后通过网页调用该函数,实现检测网络的目地。目前的问题是在执行时
    有dos窗口闪出,我想知道如何不让dos窗口出现
      

  2.   

    我直接把它加到jsp页面中,没有dos窗口跳出。
      

  3.   

    我在JDK上运行 却有DOS窗口出现 速度较快 下面是我写的函数public boolean setcheck(String address,int num)
    {
     try
        {  
          InputStream ou = Runtime.getRuntime().exec("ping "+address+" -n "+num+" ").getInputStream();
          InputStreamReader ir= new InputStreamReader(ou);
          BufferedReader in = new BufferedReader(ir);
        
          while((name=in.readLine())!=null)
          { 
            if(name.startsWith("Request timed out."))
              {
               state=false;
              }
            if(name.startsWith("Reply from"))
              { 
                state=true;
              }        
          }      
        }
    catch(Exception e)
        {      
        }   
                return state;
    }
    调用页面
    <% 
          boolean state=ConBean.setcheck(address,1); 
          if(state)
           { %>       
          <td width="3%" align="center">  </td><td width="13%" align="center"><img src=".//WIN98.ICO" width="32" height="32"><br>
       <font color="green"> <% 
              out.println( ""+address+"");
              %>       </fond> </td>
        <%
           }
           
         if(!state)
          { 
             %>      
           <td width="3%" align="center">  </td><td width="13%" align="center"><img src=".//WIN98.ICO" width="32" height="32"><br>
            <font color="red"> <% out.println(""+address+"");
            }    
            %>  
            </fond>    
            </td>
            <%
            if(i%5==0)  
            {  %>
            <td width="3%" align="center">  </td></tr>
            <tr><td width="3%" ></td><td width="10%" align="center"></td></tr><tr>
            <%
            i=0;
            }
       }
     %>