我在Tomcat的根文件夹下有Jsp文件,我想要包含另一个放在webapps文件夹下的jsp文件。我正在尝试使用代码
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<jsp:include page="../docs/index.html"/>
</body>
</html>
我收到以下异常
HTTP Status 500 - An exception occurred processing JSP page /trail.jsp at line 16
type Exception report
message An exception occurred processing JSP page /trail.jsp at line 16
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /trail.jsp at line 16
13: </head>
14: <body>
15: <h1>Hello World!</h1>
16: <jsp:include page="../docs/index.html"/>
17: </body>
18: </html>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
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:728)
root cause
java.lang.NullPointerException
org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
org.apache.jsp.trail_jsp._jspService(trail_jsp.java:73)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
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:728)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.42 logs.
请帮我在tomcat的webapps文件夹下包含jsp。
提前致谢
答案 0 :(得分:0)
webapps / doc /中的文件与trail.jsp不在同一个上下文中。您不能包含来自其他上下文的jsp。虽然根据代码,您尝试包含静态文件。如果这是正确的,请更新您的说明。
答案 1 :(得分:0)
从目录WEB-INF/views
(src/main/webapp/WEB-INF/views
)
<jsp:include page="/WEB-INF/views/index.jsp" />