Language/JSP

[JSP] el을 이용한 절대경로 설정

별토끼. 2017. 7. 18. 11:56
반응형



[JSP] el을 이용한 파일경로




- bootstrap, jquery등을 로딩할 때 경로는 매우 중요하다.

- 이 때는 절대경로를 쓰는 것이 훨-씬 좋다.

- 절대경로를 이용하면 오류 가능성이 훨씬 낮아진다.


- el을 이용하여 contextPath를 가져온 후 폴더 및 파일 경로를 입력하면 편리하다!


${pageContext.request.contextPath }



  • 상대경로 이용할 경우

- <script src="resource/js/jquery-3.2.0.js"></script>

- <link rel="stylesheet" href="resource/css/bootstrap.css" />



  • 절대경로 이용할 경우
- <script src="${pageContext.request.contextPath}/resource/js/jquery-3.2.0.js"></script>
- <link rel="stylesheet" href="${pageContext.request.contextPath}
/resource/css/bootstrap.css" />



cf > java를 이용한 절대경로 설정

<% String cPath=request.getContextPath(); %>

<link rel="stylesheet" href="<%=cPath %>/resource/css/bootstrap.css" />

<script src="<%=cPath%>/resource/js/jquery-3.2.0.js"></script>





반응형