0

我在 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。

提前致谢

4

2 回答 2

0

webapps/doc/ 中的文件与 trail.jsp 不在同一个上下文中。您不能包含来自另一个上下文的 jsp。尽管根据您尝试包含静态文件的代码。如果这是正确的,请更新您的描述。

于 2013-08-23T07:42:01.337 回答
0

从目录WEB-INF/views( src/main/webapp/WEB-INF/views)尝试

<jsp:include page="/WEB-INF/views/index.jsp" />

网页应用结构

于 2013-08-23T07:47:04.977 回答