🌱 http/https, 서버주소, 포트 가져오기
ex)
String path=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort();
/*
만약에 path가 http://localhost:8080 이라면
request.getScheme() 은 http 반환
request.getServerName() 은 localhost 반환
request.getServerPort() 는 8080 반환
*/
❕ 참고로 운영용 도메인 주소보면 port가 보이지 않아 위의 예시에서 request.getServerPort()가 적용될까 싶지만, 사실 포트는 숨겨져서 붙고있기 때문에 걱정안해도 된다.
ex) www.naver.com:80
🌱 전체 주소/일부 경로 가져오기
ex)
String path1 = request.getRequestURL();
String path2 = request.getRequestURI();
/*
만약에 path1이 http://localhost:8080/board/main.do 이라면
request.getRequestURL() 은 http://localhost:8080/board/main.do 반환
만약에 path2가 http://localhost:8080/board/main.do 이라면
request.getRequestURL() 은 /board/main.do 반환
*/