1. 程式人生 > >struts2學習中遇到的坑之${pageContext.request.contextPath}錯誤

struts2學習中遇到的坑之${pageContext.request.contextPath}錯誤

錯誤提示
Stacktrace:] with root cause
javax.el.PropertyNotFoundException: Property ‘ContextPath’ not found on type org.apache.struts2.dispatcher.StrutsRequestWrapper
這裡寫圖片描述
很明顯,路徑寫錯了
${pageContext.request.contextPath}
是JSP取得絕對路徑的方法,等價於<%=request.getContextPath()%> 。
也就是取出部署的應用程式名或者是當前的專案名稱
如果我的專案名稱是demo在瀏覽器中輸入為

http://localhost:8080/demo/index.jsp ${pageContext.request.contextPath}或<%=request.getContextPath()%>取出來的就是/demo,而”/”代表的含義就是http://localhost:8080
故有時候專案中這樣寫${pageContext.request.contextPath}/index.jsp