JSP URL주소 가져오는 함수 정리

박중연·2024년 2월 26일

JSP URL주소 가져오는 함수 정리

 

1. request.getContextPath()

설명: 프로젝트 Path만 가져옵니다.

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

[return]/project 

 

2.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

 

3.request.getRequestURL()

설명: 전체 경로를 가져옵니다.

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

 

4.request.ServletPath()

설명: 전체 경로를 가져옵니다.

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

 

5.request.getRealPath()

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

request.getRealPath() 

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

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

 

profile
개발자로 취업하기

0개의 댓글