개인공부/JSP

서블릿에서 request으로 요청 URL 확인하기

ELpsy 2022. 10. 13. 09:59

JSP 자바 코딩에서 다양한 url 주소 가져오는 함수가 있습니다

 

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

request.getContextPath() 

예)  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()

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

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

 

파일명만 가져옵니다.

request.ServletPath() 

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

[return] /list.jsp

 

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

request.getRealPath() 

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

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

출처: https://yi-chi.tistory.com/12 [2chi:티스토리]