随笔 - 7, 文章 - 12, 评论 - 17, 引用 - 0
数据加载中……

java调用url的两种方式

一、在java中调用url,并打开一个新的窗口

String url="http://10.58.2.131:8088/spesBiz/test1.jsp";
String cmd = "cmd.exe /c start " + url;

try {
 Process proc = Runtime.getRuntime().exec(cmd);
 proc.waitFor();
}
catch (Exception e)
{
 e.printStackTrace();
}

二、在java中调用url,后台调用。并取得返回值
URL U = new URL("http://10.58.2.131:8088/spesBiz/test1.jsp");
URLConnection connection = U.openConnection();
   connection.connect();
  
   BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
   String line;
   while ((line = in.readLine())!= null)
   {
    result += line;
   }
   in.close();

posted on 2007-12-29 11:33 刘浪 阅读(3593) 评论(0)  编辑  收藏 所属分类: code


只有注册用户登录后才能发表评论。


网站导航: