이 메소드는 더 이상 문제를 사용하는 것이 권장되지 않습니다 .getRealPath () 메소드 대신 :
request.getSession (). getServletContext (). getRealPath ()
Servlet에서 this.getServletContect (). getRealPath ()를 사용하십시오
Struts에서 this.getServlet (). getServletContext (). getRealPath ()를 사용하십시오
servletactionContext.getRequest (). getRealPath ()를 사용하여 사용;
위의 세 가지는 서버에서 현재 실행중인 파일의 모든 절대 경로입니다.
요청에서 다양한 경로 요약을 받으십시오
request.getRealPath ( "url"); // 가상 디렉토리는 실제 디렉토리에 매핑됩니다.
request.getRealPath ( "./"); // 웹 페이지가있는 디렉토리
request.getRealPath ( "../"); // 웹 페이지가있는 디렉토리의 이전 디렉토리
request.getContextPath (); // 응용 프로그램 웹 디렉토리의 이름입니다
예를 들어, http : // localhost : 7001/bookstore/
/ bookstore/ => [ContextPath] (request.getContextPath ())
웹 프로젝트의 전체 경로를 얻으십시오
문자열 strdirpath = request.getSession (). getServletContext (). getRealPath ( "/");
프로젝트 이름 테스트를 예로 들어보십시오.
(1) 프로젝트 이름이 포함 된 현재 페이지의 전체 경로를 가져옵니다. request.getRequesturi ()
결과 : /test/test.jsp
(2) 프로젝트 이름 가져 오기 : request.getContextPath ()
결과 : /테스트
(3) 현재 페이지가있는 디렉토리에서 전체 이름을 가져옵니다. request.getServletPath ()
결과 : 페이지가 jsp directory /test/jsp/test.jsp에있는 경우
(4) 페이지가 위치한 서버의 전체 경로를 가져옵니다.
결과 : d : /resin/webapps/test/test.jsp
(5) 페이지가 위치한 서버로 절대 경로를 가져옵니다. abspath = new java.io.file (application.getRealPath (request.getRequesturi ()). getParent ();
결과 : d :/수지/웹 apps/테스트
2. 수업에서 길을 얻으십시오.
(1) 클래스로가는 절대 경로 : class.class.getClass (). getResource ( "/"). getPath ()
결과 :/d :/test/webroot/web-inf/classment/pack/
(2) 프로젝트로가는 길을 얻으십시오 : System.GetProperty ( "user.dir")
결과 : d :/test
3. 서블릿에서 경로를 얻으십시오.
(1) 프로젝트 디렉토리를 가져옵니다 : request.getSession (). getServletContext (). getRealPath ( "") 매개 변수는 패키지 이름에 지정할 수 있습니다.
결과 : e :/tomcat/webapps/test
(2) IE 주소 표시 줄 주소 : request.getRequestUrl ()
결과 : http : // localhost : 8080/test/test
(3) 상대 주소 받기 : request.getRequesturi ()
결과 : /테스트 /테스트