경로 문제 정리
7169 단어 서버
경로 문제 정리
내 홈페이지 www.csxiaoyao.com
1 "/" 의 차이점
1.1 서버 및 클라이언트 브라우저
서버/웹 루트의 루트 디렉터리 (항목 이름 필요 없음) 브라우저/웹 앱의 루트 디렉터리 (항목 이름 쓰기 필요)
1.2 응용 사례
전달
request.getRequestDispatcher("/target.html").forward(request, response);
리디렉션 요청
response.sendRedirect("/project/target.html");
html 페이지 초연결
response.getWriter().write("<html><body><a href='/project/target.html'> a>body>html>");
html 페이지의form 제출 주소
<form action='/project/target.html'>
2 서버 측 상대 경로에서 파일 읽기
2.1 “.” tomcat/bin 디렉터리로 이동
//
File("./src/db.properties");
2.2 웹 응용 프로그램에서 자원 파일을 불러오는 방법
메서드1: getRealPath() 읽기, 리소스 파일의 절대 경로 반환
String path = this.getServletContext().getRealPath("/WEB-INF/db.properties");
File file = new File(path);
FileInputStream in = new FileInputStream(file);
메서드 2: getResourceAsStream () 에서 리소스 파일을 가져와 입력 흐름을 반환합니다.
InputStream in = this.getServletContext().getResourceAsStream("/WEB-INF/db.properties");
//
Properties prop = new Properties();
prop.load(in);
String user = prop.getProperty("user");
String password = prop.getProperty("password");
3 운영 체제 차이점
3.1 공통점
절대 경로: 이 파일의 전체 경로는 일반적으로 디스크 문자로 시작됩니다.상대 경로: 상대 경로는 자원 파일이 현재 프로그램이 있는 경로를 기준으로 합니다...현재 경로...이전 레벨 경로
3.2 디렉터리 구분자 차이
윈도우즈 기기의 디렉터리 구분자는\이고, linux 기기의 디렉터리 구분자는/이며, 윈도우즈에서\와/를 디렉터리 구분자로 사용할 수 있으며,/를 쓸 때 하나만 쓰면 경로 예시가 됩니다.
----linux----
/home/sunshine/data.txt
./
../
----windows----
"\" "\\"
E:\sunshine\a.txt
E:/sunshine/a.txt
E:
../../
System.out.println(" :"+ File.separator);
System.out.println(" :"+ file4.getAbsolutePath());//D:\Workspaces\java_test\.
File parentFile = new File("E:\\");
File file1 = new File("E:"+File.separator+"a.txt");
File file2 = new File("E:/a.txt");
File file3 = new File("E:\\","a.txt");
File file4 = new File(".");
File file5 = new File("..\\..\\a.txt");
4 URI、URL
URI:Uniform Resource Identifier, Uniform Resource 식별자 URL:Uniform Resource Locator, Uniform Resource 포지셔닝 문자
URL은 URI의 특례입니다. URL은 유일하게 자원을 포지셔닝할 수 있습니다[URI 예시]mailto:[email protected][URL 예제]file:///E:/sunshine/a.txt http://www.csxiaoyao.com/ ftp://home.ustc.edu.cn
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
집 서버 설계 (하드웨어 편)자신의 Redmine이나 ownCloud를 운용하기 위해 사쿠라 VPS, DigitalOcean, OpenShift 등을 놀랐습니다만, 침착 해 왔으므로 현상을 정리하고 싶습니다. 먼저 하드웨어 구성을 정리합니다. ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.