IT 유용한 정보

[ Spring ] request.getContextPath() ,request.getRequestURI() 등 url 주소 가져오는 함수

JooKit 주킷 2021. 8. 4. 19:45
목차 접기
728x90
반응형

request.getContextPath() 함수 = 프로젝트 Path만 가져옵니다.

 

예)  http://localhost:8080/project/list.jsp

 

[return]        /project 를 가져옵니다 ㅎ 

 

 

 

 

 

 

 

 

request.getRequestURI() 함수 = 프로젝트 + 파일경로까지 가져옵니다.

 

 

예)  http://localhost:8080/project/list.jsp

 

[return]        /project/list.jsp  를 가져옵니다 ㅎ

 

String url = request.getRequestURI.split("/");

String Name = url[url.length -1];       // list.jsp

 

 

 

 

 

 

 

 

 

 

request.getRequestURL() 함수 = 전체 경로를 가져옵니다.     (L만 바뀜)

 

예) http://localhost:8080/project/list.jsp

 

[return]   http://localhost:8080/project/list.jsp

 

 

 

 

 

 

 

 

 

 

 

request.ServletPath() 함수 = 파일명만 가져옵니다.

 

예) http://localhost:8080/project/list.jsp

 

[return] /list.jsp

 

 

 

 

 

 

 

request.getRealPath("") 함수 =

서버 or 로컬 웹 애플리케이션 절대결로 가져옵니다.

 

예) http://localhost:8080/projectname/list.jsp

 

[return]         c:\project\webapps\projectname\



출처: https://yi-chi.tistory.com/12 [2chi]

 

request.getContextPath() ,request.getRequestURI() 등 url 주소 가져오는 함수

JSP 자바 코딩에서 다양한 url 주소 가져오는 함수를 정리할게요 ㅎ request.getContextPath() 함수 = 프로젝트 Path만 가져옵니다. 예)  http://localhost:8080/project/list.jsp [return]        /proj..

yi-chi.tistory.com

 

728x90
반응형
LIST