> Java > java지도 시간 > 본문

Java.net URI

PHPz
풀어 주다: 2024-08-30 16:04:58
원래의
310명이 탐색했습니다.

Java.net 패키지는 해당 구성 요소에서 URI 인스턴스를 생성하거나 해당 구성 요소의 문자열 형식을 구문 분석하여 URI 인스턴스의 여러 구성 요소에 액세스하고 검색하는 메서드가 포함된 클래스 URI를 제공합니다.

광고 이 카테고리에서 인기 있는 강좌 JAVA MASTERY - 전문 분야 | 78 코스 시리즈 | 15가지 모의고사

무료 소프트웨어 개발 과정 시작

웹 개발, 프로그래밍 언어, 소프트웨어 테스팅 등

URI란 무엇인가요?

Uniform Resource Identifier에는 특정 리소스 식별에 도움이 되는 일련의 문자가 있습니다. 또한 특정 프로토콜의 도움으로 네트워크를 통한 리소스 표현의 상호 작용을 돕습니다. 이 특정 수업에 대한 자세한 내용은 아래 섹션에서 논의됩니다.

구문

아래는 java.net URI 클래스의 구문입니다.

scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]
로그인 후 복사
  • 구성표: 이 구성 요소는 URI와 연결된 특정 프로토콜을 배치합니다. 일부 구성표에서는 "//"가 필요하지만 다른 구성표에서는 사용되지 않습니다.
  • authority: 이 구성 요소는 인증 부분, 호스트, 콜론 ':' 뒤에 오는 포트 번호 등 다양한 구성 요소로 구성됩니다. 첫 번째 섹션의 인증 섹션은 사용자 이름과 비밀번호로 구성됩니다. 동시에 두 번째 섹션 호스트는 IP 주소 중 하나일 수 있습니다. 세 번째 섹션 포트 번호는 선택 사항입니다.
  • 경로: 특정 리소스에 대한 서버 내에 존재하는 주소로 구성된 문자열을 갖는 구성 요소입니다.
  • query : 이 컴포넌트는 앞 부분의 '?' 물음표를 이용하여 특정 리소스를 찾는 쿼리를 사용한 비계층적 데이터입니다.
  • fragment: 보조 리소스를 식별하는 구성 요소입니다. 페이지 등에 있는 제목이나 부제목일 수 있습니다.

Java.net URI 클래스는 어떻게 작동하나요?

이미 논의한 바와 같이 URI는 URL(Uniform Resource Locator)로 알려져 있으며 위치와 이름을 사용하여 이미지, 캐스케이드 스타일 시트 파일, 비디오 등과 같은 웹 리소스를 식별하는 데 도움이 됩니다. 여기서 위치는 특정 리소스에 액세스하거나 검색하는 메커니즘입니다. 예를 들어  HTTP://, FTP:// 등이 위치입니다. 또한 "이름"은 특정 리소스의 전역 특정 이름입니다. 다음 웹 주소 https://samplepath/path/to/video.mkv가 비디오를 검색하는 예를 살펴보겠습니다. 여기서 이 특정 주소의 샘플 경로/경로/to/video.mkv 섹션은 URN 또는 이름입니다.

건축자

다음은 URI의 5가지 생성자입니다.

  • URI(String st): 문자열 st를 파싱하여 URI를 생성합니다.
  • URI( String Scheme , String str, String frag): URI는 주어진 구성 요소로 구성됩니다.
  • URI( String schm, String userinf, String Host, int portnum, String path, String query, String frag): 계층적 URI는 지정된 구성 요소로 구성됩니다.
  • URI( String schm, String Host, String path, String frag): 지정된 구성 요소로 계층적 URI가 구성됩니다.
  • URI( String schm, String suthorty, String path, String query, String frag): 지정된 구성 요소로부터 계층적 URI가 구성됩니다.

Java.net URI에 대한 메서드

다음은 여러 작업을 수행하는 URI 클래스의 다양한 메서드입니다.

  • compareTo(URI ur): This URI will be compared with another URI.
  • create(String str): A URI will be created on parsing the string str
  • equals(Object obj): The URI will be tested for equality with the object obj
  • getAuthority(): Returns the URI’s authority component, which is decoded.
  • getFragment(): Returns the URI’s fragment component, which is decoded.
  • getHost(): Returns the URI’s host component, which is decoded.
  • getPath(): Returns the URI’s path component, which is decoded.
  • getPort(): URI port number will be returned.
  • getQuery(): Returns the URI’s query component, which is decoded.
  • getRawAuthority(): Returns the URI’s raw authority component.
  • getRawFragment(): Returns the URI’s raw fragment component.
  • getRawPath(): Returns the URI’s raw path component.
  • getRawQuery(): Returns the URI’s raw query component.
  • getRawSchemeSpecificPart(): Returns the URI’s raw scheme-specific part.
  • getRawUserInfo(): Returns the URI’s raw user information component.
  • getScheme(): Returns the URI’s scheme component.
  • getSchemeSpecificPart(): Returns the URI’s scheme-specific part which is decoded.
  • getUserInfo(): Returns the URI’s user information component which is decoded.
  • hashCode(): Returns URI hash code value.
  • isAbsolute(): Checks whether the URI provided is absolute or not.
  • isOpaque(): Checks whether the URI provided is opaque or not.
  • normalize(): URI path gets normalized on calling this method.
  • parseServerAuthority(): This method parses the authority component into user information, port, and host components.
  • relativize(URI uri): Given URI gets relativized to the URI specified.
  • resolve(String str): A new URI is constructed by parsing the string mentioned and resolving the same against the URI.
  • resolve(URI uri): The given URI is resolved against the URI.
  • toASCIIString(): Content of the URI mentioned is returned as a US-ASCII string.
  • toString(): Content of the URI mentioned is returned as a string.
  • toURL(): A URL gets constructed from the URI mentioned.

Examples to Implement Java.net URI

Now, let us see a sample program of java.net uri class.

Java program to demonstrate several methods in the class java.net.uri. //Java Program to demonstrate methods of URI class

Code:

import java.net.*;
class URIexample
{
public static void main(String[] args) throws Exception
{
String str = "https://www.google.com/search?q=educba+treemap&oq=educba+treemap+&aqs=chrome..69i57j69i60.12298j1j7&sourceid=chrome&ie=UTF-8";
// Creation of new URI by parsing the string
URI exampleuri = new URI(str);
//different methods of <u>uri</u> class
System.out.println("Host of the URI is:  " + exampleuri.getHost());
System.out.println("Port of the URI is: = " + exampleuri.getPath());
System.out.println("Raw Path of the URI is: = " + exampleuri.getRawPath());
System.out.println("Path of the URI is: = " + exampleuri.getPath());
System.out.println("Query of the URI is: = " + exampleuri.getQuery());
System.out.println("Raw Query of the URI is: = " + exampleuri.getRawQuery());
System.out.println("Fragment of the URI is: = " + exampleuri.getFragment());
System.out.println("Raw Fragment of the URI is: = " + exampleuri.getRawFragment());
//another uri in order to demonstrate the method compareTo and equals
URI exampleuri2 = new URI(str + "fr");
System.out.println("CompareTo exampleuri2=" + exampleuri.compareTo(exampleuri2));
System.out.println("Equals of the URI is: = " + exampleuri.equals(exampleuri2));
System.out.println("Hashcode of the URI is: " + exampleuri.hashCode());
System.out.println("toString of the URI is: " + exampleuri.toString());
System.out.println("toASCIIString of the URI is: " + exampleuri.toASCIIString());
}
}
로그인 후 복사

Output: In this program, different methods of java.net.uri class are used and displayed results based on that.

Java.net URI

위 내용은 Java.net URI의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!