package com.webkfa.test; import java.net.HttpURLConnection; import java.net.URL; public class Test { /** * 返回重定向地址 * @param url * @return */ public static String urlto320url(String url){ String tempstr=url; HttpURLConnection conn=null; try{ URL durl = new URL(url); conn = (HttpURLConnection) durl.openConnection(); tempstr=conn.getURL().toString(); durl = new URL(url); conn = (HttpURLConnection) durl.openConnection(); tempstr=conn.getURL().toString(); }catch(Exception e){ e.printStackTrace(); }finally{ if(conn!=null)conn.disconnect(); } System.out.println(tempstr); return tempstr; } public static void main(String[] args){ //要自己把http://www.webkfa.com换成有302的地十 String url=urlto320url("http://www.webkfa.com"); System.out.println(url); } }