본문 바로가기

Programming/Web

[Web] requestPath

requestPath


HTTP URI

URI : http://[host]:[port][/requestPath]?[get 방식의 경우 queryString]

requestPath : contextPath, ServletPath, PathInfo


한 서버에서 여러가지의 프로젝트를 돌린다던가 구분을 위해 contextPath를 나누어 

사용을 하게 되는데 이 contextPath가 변경이 된다면 페이지마다 링크를 일일히 

바꿔줘야하는 일이 생긴다. 그래서 이를 대비하기 위해 ${pageContext.request.contextPath}이다.


<a href="${pageContext.request.contextPath/list.do">게시판</a>

이렇게 링크부분에 넣어두면 ${pageContext.request.contextPath} 이 부분에 

서버에서 설정되어 있는 contextPath가 들어가게 된다.


주의할 점은 servlet 2.4 이하 버전까지는 EL을 지원하지 않기 때문에 <c:out>을 통해서 

출력해야 한다고 한다.

<a herf="<c:out value='${pageContext.request.contextPath}'/>/list.do">게시판</a>


request.getContextPath()

프로젝트의 Context path명을 반환

Request : http://localhost:8080/sample/index.jsp

Return : /sample


request.getRequestURI()

웹의 전체경로(프로젝트명 + 파일경로)를 반환

Request : http://localhost:8080/sample/index.jsp

Return : /sample/index.jsp


request.getRealPath("/")

서버나 로컬의 웹어플리케이션 서버의 docBase를 반환

Request : http://localhost:8080/sample/index.jsp

Return : D:\MyProject\webapps\sample\






'Programming > Web' 카테고리의 다른 글

[Web] GET / POST 한글 처리  (0) 2015.01.26
[Web] web.xml 에러페이지 처리  (0) 2015.01.09
[Web] URI, URL, URN 이란?  (0) 2014.09.18
[Web] Servlet/JSP Programming  (0) 2014.09.18
[Web] HTTP Protocol 과 REST  (0) 2014.09.02