根据url抓取jsp内容
根据一个jsp地址,抓取jsp里的内容
代码:
1 package com.base.util; 2 3 import java.io.BufferedReader; 4 import java.io.IOException; 5 import java.io.InputStreamReader; 6 import java.net.HttpURLConnection; 7 import java.net.MalformedURLException; 8 import java.net.URL; 9 10 public class FunctionUtil { 11 12 public static String getHtml(String urlString) { 13 try { 14 StringBuffer html = new StringBuffer(); 15 URL url = new URL(urlString); 16 HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 17 conn.setDoOutput(true); 18 InputStreamReader isr=new InputStreamReader(conn.getInputStream(),"utf-8"); 19 BufferedReader br =new BufferedReader(isr); 20 String temp; 21 while ((temp = br.readLine()) != null) { 22 html.append(temp).append("\n"); 23 } 24 br.close(); 25 isr.close(); 26 return html.toString(); 27 } catch (Exception e) { 28 e.printStackTrace(); 29 return null; 30 } 31 } 32 }
使用:
1 getHtml(rootpath+"/page/xzsp/sp_webService.jsp")