当前位置: 首页 > news >正文

网站建设业务员长沙网站建设搭建

网站建设业务员,长沙网站建设搭建,公司logo如何设计,辽宁省交通建设投资集团网站【README】 本文阐述了 URL#xff0c; URI#xff0c;以及对应的java类的api#xff1b; 1.URI#xff0c;统一资源标识符#xff0c;标识互联网上的某个网络资源#xff0c;标识方式如 名称#xff0c;位置等#xff1b;就像人的标识一样#xff0c;可以通过身份证…【README】 本文阐述了 URL URI以及对应的java类的api 1.URI统一资源标识符标识互联网上的某个网络资源标识方式如 名称位置等就像人的标识一样可以通过身份证或学生证号或社保号码等来标识但不一定靠位置来标识2.URL 统一资源定位符唯一标识一个资源在internet上的位置仅靠位置来标识所以 URL 是 URI标识网络资源的一种方式即 URI可标识的资源范围比URL大3.URL是一种URI 4. URI 由 URL URN统一资源名称组成 【1】URI统一资源标识符 1URI采用特定语法标识网络资源URI 是一个标识资源的字符串而已 2URI标识语法  模式:模式特定部分 2.1模式包括可以理解为资源协议 datafileftphttptelnet 2.2模式特定部分采用一种层次结构如 //authority/path?k1v1k2v2#anchor 其中 authority 表示授权机构如 www.baidu.com 即服务器域名path 表示资源路径? k1v1k2v2 表示查询字符串#anchor 锚点表示html页面的某个元素【2】URL统一资源定位符 1URL 是一种URI 除了标识一个网络资源还提供资源的网络位置以便查找 客户端可以用它获取资源 2资源的网络位置包括 协议如http服务器主机域名端口路径查询参数锚点或有 3URL语法如下协议://userInfohost:port/path?query#fragment 用户信息 主机hostport端口合并在一起构成了权威机构路径是指向服务器上的一个特定目录或文件类似于unix的文件系统路径查询字符串向服务器提供了附加参数片段 指向远程资源的某个特定部分【3】URL java类例子 【3.1】创建URL Testpublic void f1() throws MalformedURLException {URL url new URL(http://www.baidu.com);System.out.println(url);System.out.println(url.getProtocol());System.out.println(url.getPort());System.out.println(url.getAuthority());}http://www.baidu.com http -1 www.baidu.com 【3.2】创建URL-相对地址 Testpublic void f2() throws IOException {URL url1 new URL(https://blog.csdn.net/PacosonSWJTU/article/details/120964766);URL url2 new URL(url1, 120980127); // 相对地址System.out.println(url1.getPath()); // /PacosonSWJTU/article/details/120964766System.out.println(url2.getPath()); // /PacosonSWJTU/article/details/120980127} 从url获取数据3种方式 方法1使用 URL.openStream() 方法2使用 URL.openConnection 和 URLCOnnection.getInputStream() 方法方法3使用 URL.getContent() 方法 补充URL.openStream() 方法如下 public final InputStream openStream() throws java.io.IOException {return openConnection().getInputStream(); // 获取输入流 }// 打开连接 public URLConnection openConnection() throws java.io.IOException {return handler.openConnection(this);} 3.1方法1使用openStream() 方法 Testpublic void f3() throws IOException {URL url1 new URL(https://blog.csdn.net/PacosonSWJTU/article/details/120964766);try (DataInputStream dataInputStream new DataInputStream(url1.openStream())) {int c;while((c dataInputStream.read()) ! -1) {System.out.print((char)c); // 有乱码 无法对中文进行解析}}} 改用基于UTF-8字符编码格式的 inputStreadReader 读取数据可以处理中文如下 Testpublic void f4() throws IOException {URL url1 new URL(https://blog.csdn.net/PacosonSWJTU/article/details/120964766);// 采用utf-8 编码可以解析中文字符String str null;try (BufferedReader bufferedReader new BufferedReader(new InputStreamReader(url1.openStream(), StandardCharsets.UTF_8))) {while((str bufferedReader.readLine()) ! null) {System.out.print(str);}}} 方法2使用  URL.openConnection() 和 URLCOnnection.getInputStream() 方法 读取资源 /*** title 从URL获取资源内容-url1.openConnection()urlConnection.getInputStream()方法* author xiaotang* updateTime 2021/10/31*/Testpublic void f4_2() throws IOException {URL url1 new URL(https://blog.csdn.net/PacosonSWJTU/article/details/120964766);// 采用utf-8 编码可以解析中文字符String str null;URLConnection urlConnection url1.openConnection();try (BufferedReader bufferedReader new BufferedReader(new InputStreamReader(urlConnection.getInputStream(), StandardCharsets.UTF_8))) {while((str bufferedReader.readLine()) ! null) {System.out.print(str);}}} 方法3使用 URL.getContent() 方法读取资源 /*** 通过 getContent() 获取资源内容*/Testpublic void f5() throws IOException {URL url1 new URL(https://blog.csdn.net/PacosonSWJTU/article/details/120964766);// getContent() 获取资源内容Object o url1.getContent();System.out.println(o); // sun.net.www.protocol.http.HttpURLConnection$HttpInputStream694e1548}/*** 通过 getContent(Class[] classes) 获取资源内容*/Testpublic void f6() throws IOException {URL url1 new URL(https://blog.csdn.net/PacosonSWJTU/article/details/120964766);Class?[] arr {String.class, Reader.class, InputStream.class};Object o url1.getContent(arr);System.out.println(o); // sun.net.www.protocol.http.HttpURLConnection$HttpInputStream694e1548InputStream inputStream (InputStream) o ;BufferedReader bufferedReader new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));String result null;while((result bufferedReader.readLine()) ! null) {System.out.println(result);}} 【3.3】分解URL 1URL 包括5部分 模式也称协议授权机构路径片段标识符或段或ref查询字符串 /*** title 分解URL, URL 包括5部分* author xiaotang* updateTime 2021/10/31*/Testpublic void f6() throws IOException {URL url new URL(https://blog.csdn.net/PacosonSWJTU/article/details/120904564?k1v1k2v2#anchor1);System.out.println(url.getProtocol());System.out.println(url.getHost());System.out.println(url.getPort());System.out.println(url.getFile());System.out.println(url.getPath());System.out.println(url.getRef());System.out.println(url.getQuery());System.out.println(url.getUserInfo());System.out.println(url.getAuthority()); } https blog.csdn.net -1 /PacosonSWJTU/article/details/120904564?k1v1k2v2 /PacosonSWJTU/article/details/120904564 anchor1 k1v1k2v2 null blog.csdn.net 2URL相等性 /*** title URL 相等性* author xiaotang* updateTime 2021/10/31*/Testpublic void f7() throws IOException {URL url1 new URL(https://blog.csdn.net/PacosonSWJTU/article/details/120904564?k1v1k2v2#anchor1);URL url2 new URL(https://blog.csdn.net/PacosonSWJTU/article/details/120904564?k1v1k2v2#anchor1);if (url1.equals(url2)) { // equals 底层调用了 sameFile() 方法System.out.println(url1 is equals to url2);} else {System.out.println(url1 is not equals to url2);}System.out.println(url1.sameFile(url2)); // true } 3URL 比较 // URL比较调用URl.toString() toExternalForm() toURI()Testpublic void f8() throws Exception {URL url1 new URL(http://www.baidu.com?name张三city成都#anchor2);System.out.println(url1.toString()); //System.out.println(url1.toExternalForm());URI uri2 url1.toURI(); // URL 转为 URI 类System.out.println(uri2);} 【4】URI类-统一资源标识符类 1URI是 URL的抽象不仅包括统一资源定位符URL还包括统一资源名 URN 2URI 提供了网络资源的表示但没有提供网络获取功能而URL 提供了网络资源获取功能 3URI VS URL 非常重要 若想下载一个 URL的内容应该使用URL如果想用URL 来标识而不是获取网络资源如一个 XML的命名空间就应该使用 URI类 补充URI.toURL() 可以把 URI 转为 URL URL.toURI() 可以把 URL 转为 URI 简单说URI是抽象的定义不管用什么方法表示只要能定位一个资源就叫URI 本来设想的的使用两种方法定位1URL用地址定位2URN 用名称定位。 举个例子去村子找个具体的人URI如果用地址某村多少号房子第几间房的主人 就是URL 如果用身份证号名字 去找就是URN了。 结果就是 目前WEB上就URL流行开了平常见得URI 基本都是URL。 4 URI vs URL 例子 干货 // URI vs URL URI 标识资源URL 定位资源但可能无法标识某些资源Testpublic void f14() throws Exception {URI voice new URI(tel:1-800-9988-9938); // 电话URI book new URI(urn:isbn:1-023-40287-9); // 国际标准书号URI email new URI(zhangsangoole.com); // 邮件// 打印 URISystem.out.println( 打印 URI);System.out.println(voice);System.out.println(book);System.out.println(email);// 打印 URLSystem.out.println( 打印 URL);System.out.println(new URL(http://www.baidu.com)); // http://www.baidu.com 必须以协议开头 System.out.println(new URL(tel:1-800-9988-9938)); // 会抛出异常哦System.out.println(new URL(urn:isbn:1-023-40287-9)); // 会抛出异常哦System.out.println(new URL(zhangsangoole.com)); // 会抛出异常哦} 打印结果 打印 URI tel:1-800-9988-9938 urn:isbn:1-023-40287-9 zhangsangoole.com 打印 URL http://www.baidu.com java.net.MalformedURLException: unknown protocol: tel   // 抛出异常了 【4.1】构造URI 1构建URI // 相对uriTestpublic void f11() throws Exception {URI uri new URI(https://blog.csdn.net/PacosonSWJTU/article/details/120964766);System.out.println(uri);URI uri2 uri.resolve(59483747); // 相对地址 59483747System.out.println(uri2); // https://blog.csdn.net/PacosonSWJTU/article/details/59483747} 2URI的各个部分 模式模式特定部分片段  // 获取URI属性Testpublic void f10() throws Exception {URI uri new URI(https://blog.csdn.net/PacosonSWJTU/article/details/120904564?k1v1k2张三#anchor1);System.out.println(uri.isOpaque());System.out.println(uri.getAuthority());System.out.println(uri.getFragment());System.out.println(uri.getHost());System.out.println(uri.getPath());System.out.println(uri.getPort());System.out.println(uri.getQuery());System.out.println(uri.getUserInfo());/* 获取原生数据 */System.out.println(----------------- raw -------------------);System.out.println(uri.getRawAuthority());System.out.println(uri.getRawFragment());System.out.println(uri.getRawPath());System.out.println(uri.getRawQuery());System.out.println(uri.getRawUserInfo());System.out.println(uri.getRawSchemeSpecificPart());} false // 如果 URI是一个层次URI则返回false 若URI不是层次URI即不是透明的返回true blog.csdn.net anchor1 blog.csdn.net /PacosonSWJTU/article/details/120904564 -1 k1v1k2张三 null ----------------- raw ------------------- blog.csdn.net anchor1 /PacosonSWJTU/article/details/120904564 k1v1k2张三 null //blog.csdn.net/PacosonSWJTU/article/details/120904564?k1v1k2张三 【4.2】相对uri Testpublic void f11() throws Exception {URI uri new URI(https://blog.csdn.net/PacosonSWJTU/article/details/120964766);System.out.println(uri);URI uri2 uri.resolve(59483747); // 相对地址 59483747System.out.println(uri2); // https://blog.csdn.net/PacosonSWJTU/article/details/59483747} 【4.3】uri 字符串表示 toASCIIString 对中文字符采用了 x-www-form-urlencode格式 编码 // uri 字符串表示Testpublic void f12() throws Exception {URI uri new URI(https://blog.csdn.net/PacosonSWJTU/article/details/120964766?name张三);System.out.println(uri.toString()); // https://blog.csdn.net/PacosonSWJTU/article/details/120964766?name张三 System.out.println(uri.toASCIIString()); // https://blog.csdn.net/PacosonSWJTU/article/details/120964766?name%E5%BC%A0%E4%B8%89} 【4.4】uri 编码与解码 1 x-www-form-urlencoded 1.1介绍 intro2 x-www-form-urlencode, refer2  https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Methods/POST 2编码与解码 // 对url进行编码与解码 格式为 x-www-form-urlencode ;// intro2 x-www-form-urlencode, refer2 https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Methods/POSTTestpublic void f13() throws Exception {System.out.println(URLEncoder.encode(hello world, StandardCharsets.UTF_8.displayName()));System.out.println(URLEncoder.encode(hello world 张三, StandardCharsets.UTF_8.displayName())); // 编码String str URLEncoder.encode(hello world 张三, StandardCharsets.UTF_8.displayName());// 编码- helloworld%E5%BC%A0%E4%B8%89String decodedStr URLDecoder.decode(str, StandardCharsets.UTF_8.displayName());// 解码-hello world 张三System.out.println(decodedStr);} 3url编码方式 3.1背景 在发明web时unicode 还没有完全普及所以并不是所有系统都可以处理 本中文之类的字符为了解决这个问题URL 中使用的字符必须来自 ASCII的一个固定的子集包括 大写字母 A-Z‘小写字母 a-z 数组 0-9标点符号字符  - _ . ! ~ * ( , ) 等 3.2url编码方式如下 除了 ascii数字字母和前面指定的标点符号外所有其他字符都要转换为字节每个字节要写为 百分号后面加两个16进制数字 空格是一种特殊情况 因为它太普遍了除了编码为 %20还可以编码为 为加号加号本身编码为 %2B
http://www.yutouwan.com/news/116325/

相关文章:

  • 网站模板登录模块可以做物理试验的网站有哪些
  • 网站如何悬挂备案号周村网站制作价格低
  • 一起做网站吧杭州企业建站
  • 为什么打不开中国建设银行网站网站功能设计
  • 信阳做房产哪个网站好用企业网站 备案 网站名称
  • 网站建设-上寻模板天猫网站建设
  • 网站建设哪家好 万维科技wordpress主题开发出
  • 保亭县住房城市建设局网站wordpress cpu
  • 自己做网站需要什么技术广州乐地网站建设
  • 问答网站模板下载自动生成海报的网站
  • 深圳网站建设找哪家好做网站得花多少钱
  • 手机网站欢迎页面设计网站域名被抢注做商标
  • 合肥网站设计goz网站建设销售需要哪些
  • 网站建设公司有哪些比较知名的网站备案需要准备什么
  • 上传自己做的网站可以做彩票广告的网站吗
  • 做笔记的网站源码怎样帮人做网站挣钱
  • 凡科网做网站的图片涿州规划建设局网站
  • 网站维护包括云设计平台
  • 做死活题网站wordpress pdf
  • 新手学做网站 视频百度网盘北京网络推广外包公司排行
  • 做网站外贸怎么找客户wordpress 评论关闭
  • 郑州响应式建站wordpress新浪图床会挂吗
  • 金溪那里可以做网站展开网站建设
  • 定制型网站建设平台wordpress快递模板下载
  • WordPress智能友链审核标题优化方法
  • 广东双语网站建设价格建网站用什么软件
  • 关于校园网站升级建设的报告九脉堂是做网站的
  • 适合seo的建站系统商丘网吧什么时候恢复营业
  • 旅游设计网站公司网站大顶图怎么做
  • 优质的响应式网站建设2021年