首页  :: 新随笔  :: 管理

使用java的URL类解析URL地址

Posted on 2012-11-14 09:45  季枫  阅读(14944)  评论(0编辑  收藏  举报
mport java.net.*;

import java.io.*;

public class ParseURL {

public static void main(String[] args)

throws Exception {

URL aURL = new URL("http://java.sun.com:80/docs/books/tutorial" + "/index.html?name=networking#DOWNLOADING");

System.out.println("protocol = " + aURL.getProtocol());

System.out.println("authority = " + aURL.getAuthority()); System.out.println("host = " + aURL.getHost());

System.out.println("port = " + aURL.getPort());

System.out.println("path = " + aURL.getPath());

System.out.println("query = " + aURL.getQuery());

System.out.println("filename = " + aURL.getFile());

System.out.println("ref = " + aURL.getRef());

}

}

 

ut:ut:protocol = http
ut:ut:authority = localhost:8080
ut:ut:host = localhost
ut:ut:port = 8080
ut:ut:path = /UT2.0/login.action
ut:ut:query = null
ut:ut:filename = /UT2.0/login.action
ut:ut:ref = null

智读 | 成都会领科技有限公司官网 | 智读App下载 | 每天听本书的博客 | |