자바 가 프로그램 이나 프로젝트 경 로 를 가 져 오 는 데 자주 사용 되 는 방법
1313 단어 자바
1. 임의의 class 에서 호출:
this.getClass().getClassLoader().getResource("/").getPath();
// classes
// : E:\eclipseM9/workspace/tree/WEB-INF/classes/
이 방법 도 웹 환경 에서 경 로 를 확정 하지 않 아 도 비교적 쓰기 좋다.
2 servlet 의 init 방법 에서
String path = getServletContext().getRealPath("/");
// web
// :E:\eclipseM9\workspace\tree\
//tree web
3. 웹 루트 의 컨 텍스트 환경 가 져 오기
request.getContextPath();
// /tree web root context
/*jsp */
path=request.getRealPath("");
/* jbossWEB warUrl=.../tmp/deploy/tmp14544test-exp.war/*/
path=C:\jboss-4.0.5.GA\server\default\tmp\deploy\tmp14544test-exp.war\
String path = (String)request.getContextPath();
/* (test) path=/test*/
String path = request.getRequestURI();
/* path=/test/admin/admindex.jsp*/
String savePath=request.getRealPath(request.getServletPath());
/* */
//JAVA
File file=new File(".");
String path=file.getAbsolutePath();
path=file.getPath();
/* jboss path=C:\jboss-4.0.5.GA\bin\*/
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.