javax.servlet.ServletException: File "/xml/hyperLinkList.jsp" not found

报错信息如下:大家集思广益

后来我找到报错的原因了:

<jsp:include page="${pageContext.request.contextPath}/hyperLinkList.jsp"></jsp:include>这句话导致的报错,原因就是这里使用了EL表达式,${pageContext.request.contextPath}这个EL表达式导致报错的,因为<jsp:include page="${pageContext.request.contextPath}/hyperLinkList.jsp"></jsp:include>这句话是写在home.jsp页面中的,


而我们知道jsp最终会转译成一个Servlet,我们可以去看看home.jsp页面转译后的Servlet。在tomcat目录\work\Catalina\localhost\你的项目名称\org\apache\jsp目录下,可以找到home.jsp页面转译后的这个Servlet,名字叫home_jsp.java。


打开home_jsp.java这个文件,可以看到下面的代码,home.jsp页面中的<jsp:include page="${pageContext.request.contextPath}/hyperLinkList.jsp"></jsp:include>这句话被转译就会下面的这行代码,如图:用的是PageContextImpl.proprietaryEvaluate(

org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, (java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${pageContext.request.contextPath}/hyperLinkList.jsp", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null, false), out, false);


所以说我猜测,应该是这个${pageContext.request.contextPath}导致的报错,我估计是在把home.jsp转译成Servlet的时候,只要是出现了EL表达式的地方,最终解析完成后都会给出现了EL表达式的地

方的2边都加上双引号(&quot;) ,这才导致了File &quot;/xml/hyperLinkList.jsp&quot; not found文件路径找不到的问题。${pageContext.request.contextPath}这句话是得到项目名称,你也可以理解成项目的根目录,有些人叫虚拟路径。

我的这个项目名称叫做xml,所以${pageContext.request.contextPath}这句话就得到了/xml ,所以${pageContext.request.contextPath}/hyperLinkList.jsp这句话最终转译就是/xml/hyperLinkList.jsp

就像我上面猜测的那样,

在把home.jsp转译成Servlet的时候,只要是出现了EL表达式的地方,最终解析完成后都会给出现了EL表达式的地

方的2边都加上双引号(&quot;) ,所以最终就转译成了&quot;/xml/hyperLinkList.jsp&quot;这个路径了,而我们项目中根本就没有叫&quot;/xml/hyperLinkList.jsp&quot;这个名字的页面!这就是报错的原因,这是我的猜测!不一定就是这样,还请高手指教!谢谢!

接下来我们要做的就是,去掉${pageContext.request.contextPath}这个EL表达式,OK,我们改成

<jsp:include page="/hyperLinkList.jsp"></jsp:include>


转译后如下图:很明显啊,去掉${pageContext.request.contextPath}这个EL表达式后,转译之后用的类都不同了,

如下图用的是JspRuntimeLibrary.include(


然后我们再在浏览器中打开home.jsp页面就不会报错了!


注意:
include指令不支持EL表达式- <%@include file="${pageContext.request.contextPath}/hyperLinkList.jsp"%>
种写法不支持,
会报错HTTP Status 500 - /testInclude.jsp (line: 50, column: 2) 

File "${pageContext.request.contextPath}/hyperLinkList.jsp" not found

include动作使用EL表达式容易出错,-
<jsp:include page="${pageContext.request.contextPath}/hyperLinkList.jsp"></jsp:include>这
种写法会报错HTTP Status 500 - javax.servlet.ServletException: 
File &quot;/xml/hyperLinkList.jsp&quot; not found


include动作(jsp:include)是支持EL表达式的写法的,但
<jsp:include page="${pageContext.request.contextPath}/SaveData2"></jsp:include>这种写Servlet路径的写法解析后会多
出一个项目名路径出来,java.io.FileNotFoundException: 
The requested resource (/xml/xml/SaveData2) is not available 最终导致找不到文件

include动作(jsp:include)的page属性支持jsp,html和Servlet路径写法
而include指令(@include)的file属性只支持jsp,html这种页面,不支持Servlet路径,也不支持EL表达式的写法

include(包含)中使用EL表达式,大家一定要多加注意和小心

type Exception report

message javax.servlet.ServletException: File &quot;/xml/hyperLinkList.jsp&quot; not found

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: javax.servlet.ServletException: File &quot;/xml/hyperLinkList.jsp&quot; not found
	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:585)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

javax.servlet.ServletException: File &quot;/xml/hyperLinkList.jsp&quot; not found
	org.apache.jasper.servlet.JspServlet.handleMissingResource(JspServlet.java:412)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:379)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
	org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
	org.apache.jsp.home_jsp._jspService(home_jsp.java:246)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.53 logs.


Apache Tomcat/7.0.53


猜你喜欢

转载自blog.csdn.net/czh500/article/details/80230594
今日推荐