在jsp的include标签中应用绝对和相对路径
在jsp的include标签中使用绝对和相对路径
jsp中的include标签可以使用相对路径和绝对路径,区别在于路径的第一个字符是否为"/",例如:
假设有如下web路径:
webRoot
│
│
├ [jsp]
│ │
│ │
│ ├ [subFolder]
│ │ │
│ │ subFile.jsp
│ │ │
│ │
│ myPage1.jsp
│ mypage2.jsp
│ │
│ │
│
global.jsp
│
│
相对路径
绝对路径
jsp中的include标签可以使用相对路径和绝对路径,区别在于路径的第一个字符是否为"/",例如:
假设有如下web路径:
webRoot
│
│
├ [jsp]
│ │
│ │
│ ├ [subFolder]
│ │ │
│ │ subFile.jsp
│ │ │
│ │
│ myPage1.jsp
│ mypage2.jsp
│ │
│ │
│
global.jsp
│
│
相对路径
<!-- I am myPage1.jsp --> <%@include file="subFolder/subFile.jsp"%> <%@include file="./myPage2.jsp"%> <%@include file="../global.jsp"%>
绝对路径
<!-- I am myPage1.jsp --> <%@include file="/global.jsp"%> <%@include file="/jsp/myPage1.jsp"%> <%@include file="/jsp/subFolder/subFile.jsp"%>