개발_웹/Java
Java | 웹 어플리케이션 경로 구하기 (ContextPath)
zuyo
2019. 5. 11. 15:16
반응형
웹 어플리케이션 경로 구하기 (ContextPath)
1. ContextPath
request.getContextPath()
프로젝트의 Context path명을 반환
요청 : http://localhost:8080/example/test.jsp
리턴값 : /example
2. RequestURI
request.getRequestURI()
전체 경로(프로젝트명+ 파일 경로) 반환
요청 : http://localhost:8080/example/test.jsp
리턴값 : /example/test.jsp
3. RealPath
request.getRealPath("/")
웹 어플리케이션의 실제 경로 반환
요청 : http://localhost:8080/example/test.jsp
리턴값 : D:\Project\webapps\example\
등..
JSP에서 현재 웹 어플리케이션 경로 구하기 (pageContext)
pageContext는 JSP의 내장객체로, 현재 JSP 페이지의 컨텍스트(Context)를 나타낸다.
<% String path = pageContext.getRequest().getContextPath() %>
처럼 사용하거나
var path = ${pageContext.request.contextPath};
처럼 사용하면 된다.
반응형