gpt4 book ai didi

java - JasperException(找不到文件)随机发生

转载 作者:太空宇宙 更新时间:2023-11-04 14:12:16 26 4
gpt4 key购买 nike

我的 java web 应用程序(java 6 和 tomcat 6)遇到问题,但我不知道如何解决它:

在 servlet 中,我将请求转发到 JSP。该 JSP 包括一些其他 JSP。有时,虽然没有发生任何变化并且 JSP 文件仍然存在,但找不到这些 JSP 之一。找不到其中包含的 JSP 似乎完全是随机的。 servlet 中抛出以下异常:

Exception: org.apache.jasper.JasperException: 

javax.servlet.ServletException: File "/theme/shared/shared-styles.jsp" not found
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:527)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:401)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
web.servlet.MainEntryServlet.processRequest(MainEntryServlet.java:39)
web.servlet.MainEntryServlet.doGet(MainEntryServlet.java:75)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:465)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Unknown Source)

Servlet 本身并不是很复杂:

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
request.getRequestDispatcher("/theme/mytheme/index.jsp").forward(request, response);
} catch (Exception exc) {
System.out.print(exc);
}
}

在“/theme/mytheme/index.jsp”中,所有 JSP 都以这种方式包含:

<jsp:include flush="true" page="../shared/shared-styles.jsp"/>

我找不到它在 99% 的情况下都能工作并且时不时随机失败的原因。

更新:我更正了index.jsp的路径。我只是在将代码复制到文本区域时犯了一个错误。

index.jsp 的完整路径:/主题/mytheme/index.jsp

shared-styles.jsp 的完整路径/theme/shared/shared-styles.jsp

最佳答案

您的绝对路径可能会导致问题,为什么不将其替换为 ${request.contextPath}

它将始终指向您的应用程序的根目录

关于java - JasperException(找不到文件)随机发生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28186718/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com