[Spring] 현재 페이지의 URL 주소 가져오기

seonjeong·2023년 4월 30일

Spring

목록 보기
16/27
post-thumbnail
import javax.servlet.http.HttpServletRequest;

HttpServletRequest request

아래와 같은 주소가 있을 경우
http://localhost:8080/template/index.jsp

request.getRequestURI(); 	// 프로젝트 경로부터 파일까지의 경로 값 ex) /template/index.jsp
request.getContextPath(); 	// 프로젝트의 경로값만 가져옴 ex) /template
request.getRequestURL(); 	// 전체 경로 가져옴 ex)http://localhost:8080/template/index.jsp
request.getServletPath(); 	// 파일명만 가져옴 ex) /index.jsp

// 아래 함수들을 조합하면 주소 정보를 만들 수 있다
request.getScheme();		// http
request.getServerName();	// localhost
request.getServerPort();	// 8080




Reference

https://dlevelb.tistory.com/576
https://reference-m1.tistory.com/297

profile
🦋개발 공부 기록🦋

0개의 댓글