새소식

인기 검색어

개인공부/JSP

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

  • -

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

'개인공부 > JSP' 카테고리의 다른 글

아파치(Apache)/톰캣(Tomcat)이란?  (0) 2023.11.13
EL 및 JSTL  (0) 2022.10.12
[JSP] PreparedStatement 와 Statement 차이점  (0) 2022.10.07
[JSP] 커넥션 풀  (0) 2022.10.07
[JSP] JavaBean  (1) 2022.09.21
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.