jsp页面中资源链接相对路径和绝对路径
相对路径
<html>
<a href="/index/home">click label2 to welcome page</a>
</html>
绝对路径
<html>
<a href="${pageContext.request.contextPath}/index/home">click label1 to welcome page</a>
</html>
问:什么时候用相对路径,什么时候用绝对路径?
答:部署项目时,采用的是根目录/
,才可以使用相对路径,否则只能采用绝对目录,在jsp页面中常用${pageContext.request.contextPath}
表示当前项目路径。