<jsp:include page="${pageContext.request.contextPath/index.jsp" ></jsp:include> 引发的错误

路径引发的错误

  如下使用项目路径对jsp页面进行获取,会报javax.servlet.ServletException: File &quot;/web/dbwx/web/public/page_top.jsp&quot; not found 错误.

  jsp的这个导入标签,根本就是服务器端自己在处理内部资源、整合资源,而不是传到客户端后,客户端再次访问来获取这个jsp页面资源,所以根本不需要web的这个项目名,

  /就代表着根目录,所以不需要添加项目的名称.

  相对css和js而言,就需要添加contextPath,静态资源是浏览器通过访问服务器来加载的,就需要web的工程名称.  

  错误代码

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="contextPath" value="${pageContext.request.contextPath}"/>

<jsp:include page="${contextPath}/views/common/script.jsp"/>
<jsp:include page="${contextPath}/views/common/stylesheet.jsp"/>

  正确代码

<jsp:include page="/views/common/script.jsp"/>
<jsp:include page="/views/common/stylesheet.jsp"/>

猜你喜欢

转载自www.cnblogs.com/chengyangyang/p/9460232.html