url 주소

지환·2023년 12월 5일
0

Jsp & Servlet

목록 보기
10/21

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:티스토리]

profile
아는만큼보인다.

0개의 댓글