Java

[java] url 주소 가져오기

uchacha 2020. 11. 11. 19:03

- @참고: dlevelb.tistory.com/576

아래와 같은 요청 받은 주소가 있을 경우

http://localhost:8080/test/index.jsp

request.getContextPath() : 프로젝트의 경로값만 가져옴 (/test)

request.getRequestURI() : 프로젝트 경로부터 파일까지의 경로값을 얻어옴 (/test/index.jsp)

request.getRequestURL() : 전체 경로를 가져옴 (http://localhost:8080/test/index.jsp)

아래와 같은 요청한 주소가 있을 경우

http://127.0.0.1:8080/REQ/req.jsp

request.getRemoteAddr() : 클라이언트의 IP 주소나 요청한 마지막 Proxy 주소를 가져옴 (127.0.0.1)

request.getRemoteHost() : 호스트 네임이나 IP 주소를 가져옴 (127.0.0.1)

request.getRemotePort() : 요청 보낸 포트 (52439)