자바
[자바] 함수로 파일 경로 가져오기 (getContextPath & getRequestURI)
imcoding
2022. 7. 30. 00:12
웹 프로젝트 작업을 할 때 JSP 와 Servlet 간 MVC 작업에서 파일의 경로를 가져와야 되는 일이 생긴다.
이 때 사용하는 함수 세 가지를 소개하겠다.
다음과 같은 주소가 있을 때,
http://localhost:8081/mission/index.jsp
1. request.getContextPath : 프로젝트 Path를 가져온다.
return : /mission
2. request.getRequestURI : 프로젝트와 파일 경로를 가져온다.
return : /mission/index.jsp
3. request.getRequestURL : 전체 주소를 가져온다.
return : http://localhost:8081/mission/index.jsp