jquery 跨域解决方案1

  1. package cn.com.ld.util;   
  2.   
  3. import java.io.BufferedReader;   
  4. import java.io.IOException;   
  5. import java.io.InputStream;   
  6. import java.io.InputStreamReader;   
  7. import java.net.HttpURLConnection;   
  8. import java.net.URL;   
  9.   
  10. /**  
  11.  * @filename: HttpAccessProxy  
  12.  * @Description: TODO  
  13.  * @author java小生  
  14.  * @date 2012-9-13 下午4:09:56  
  15.  */  
  16. public class HttpAccessProxy {   
  17.     public static String accessProxy(String pageUrl) {   
  18.         URL url;   
  19.         String pageString = "";   
  20.         InputStream is = null;   
  21.         BufferedReader br = null;   
  22.         StringBuffer sb = null;   
  23.         try {   
  24.             url = new URL(pageUrl);   
  25.             HttpURLConnection connection = (HttpURLConnection) url   
  26.                     .openConnection();   
  27.             is = connection.getInputStream();   
  28.             br = new BufferedReader(new InputStreamReader(is));   
  29.             sb = new StringBuffer();   
  30.             String line = null;   
  31.             while ((line = br.readLine()) != null) {   
  32.                 sb.append(line + "\n");   
  33.             }   
  34.             pageString = sb.toString();   
  35.         } catch (Exception e) {   
  36.             e.printStackTrace();   
  37.         } finally {   
  38.             try {   
  39.                 is.close();   
  40.                 br.close();   
  41.             } catch (IOException e) {   
  42.                 e.printStackTrace();   
  43.             }   
  44.   
  45.         }   
  46.         return pageString;   
  47.     }   
  48.   
  49.     public static void main(String[] args) {   
  50.         System.out.println(HttpAccessProxy.accessProxy("http://localhost:8080/ws/web/pages/data/json.jsp"));   
  51.     }   
  52. }  
package cn.com.ld.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * @filename: HttpAccessProxy
 * @Description: TODO
 * @author java小生
 * @date 2012-9-13 下午4:09:56
 */
public class HttpAccessProxy {
	public static String accessProxy(String pageUrl) {
		URL url;
		String pageString = "";
		InputStream is = null;
		BufferedReader br = null;
		StringBuffer sb = null;
		try {
			url = new URL(pageUrl);
			HttpURLConnection connection = (HttpURLConnection) url
					.openConnection();
			is = connection.getInputStream();
			br = new BufferedReader(new InputStreamReader(is));
			sb = new StringBuffer();
			String line = null;
			while ((line = br.readLine()) != null) {
				sb.append(line + "\n");
			}
			pageString = sb.toString();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				is.close();
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}

		}
		return pageString;
	}

	public static void main(String[] args) {
		System.out.println(HttpAccessProxy.accessProxy("http://localhost:8080/ws/web/pages/data/json.jsp"));
	}
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值