动态页面静态化

  1. package com.sohu.frontweb.searchname.util;  
  2.   
  3. import java.io.BufferedReader;  
  4. import java.io.FileOutputStream;  
  5. import java.io.IOException;  
  6. import java.io.InputStreamReader;  
  7. import java.net.HttpURLConnection;  
  8. import java.net.URL;  
  9. import java.net.URLConnection;  
  10.   
  11. public class StaticOperate {  
  12.   
  13.     public static void convert2Html(String sSourceUrl, String sDestDir,  
  14.             String sHtmlFile) throws IOException {  
  15.         int HttpResult;  
  16.         URL url = new URL(sSourceUrl);  
  17.         URLConnection urlconn = url.openConnection();  
  18.         urlconn.connect();  
  19.         HttpURLConnection httpconn = (HttpURLConnection) urlconn;  
  20.         HttpResult = httpconn.getResponseCode();  
  21.         if (HttpResult != HttpURLConnection.HTTP_OK) {  
  22.   
  23.         } else {  
  24.   
  25.             InputStreamReader isr = new InputStreamReader(httpconn  
  26.                     .getInputStream(), "GB2312");  
  27.             BufferedReader in = new BufferedReader(isr);  
  28.   
  29.             String inputLine;  
  30.             if (!sDestDir.endsWith("/"))  
  31.                 sDestDir += "/";  
  32.             FileOutputStream fout = new FileOutputStream(sDestDir + sHtmlFile);  
  33.             while ((inputLine = in.readLine()) != null) {  
  34.                 fout.write(inputLine.getBytes());  
  35.   
  36.             }  
  37.             in.close();  
  38.             fout.close();  
  39.   
  40.         }  
  41.   
  42.     }  
  43.   
  44.     public static void main(String[] args) {  
  45.         try {  
  46.             convert2Html(  
  47.                     "http://renming.sogou.com:7787/SearchName/mainAction.do?method=loadDatabaseConfig",  
  48.                     "C:/""renming.html");  
  49.         } catch (IOException e) {  
  50.             e.printStackTrace();  
  51.         }  
  52.     }  
  53.   
  54. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值