jsp include 无法在子目录中工作

发布于 2024-10-17 00:36:25 字数 3198 浏览 1 评论 0原文

我无法包含子目录中的 jsp 文件。我必须将包含子文件夹中的文件包含到测试文件夹中的文件中。

尝试了这段代码

<%@ include file="../../include/file.jsp"%> 

我在文件 ../test/sample.jsp

,但是我收到了类似 Update 的错误

org.apache.jasper.JasperException: /all.jsp(132,1) File "/../../include/file.jsp" not found
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:88)
org.apache.jasper.compiler.Parser.processIncludeDirective(Parser.java:300)
org.apache.jasper.compiler.Parser.parseIncludeDirective(Parser.java:333)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:442)
org.apache.jasper.compiler.Parser.parseFileDirectives(Parser.java:1749)
org.apache.jasper.compiler.Parser.parse(Parser.java:127)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:255)
org.apache.jasper.compiler.ParserController.parseDirectives(ParserController.java:120)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:180)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:347)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:326)
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)

:我认为问题与 tomcat 有关。当我用于将根文件夹映射为 tomcat 中的上下文,它正在工作,当我将根文件夹添加为主机时,出现问题。我想将其用作主机。

在此 tomcat 配置中它不起作用:

<Host name="abc.test"  appBase="c:\abcd"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">

        <Context path="/" docBase="c:\abcd" reloadable="true" crossContext="true">
 ..................................................................
...............................................................
</context>
</host>

但它在以下配置中起作用

<Host name="abc.test"  appBase="c:\abc"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">

<Context path="/lang" docBase="c:\subdir" reloadable="true" crossContext="true">
  ..................................................................
...............................................................
</context>

        <Context path="/" docBase="c:\subdir" reloadable="true" crossContext="true">
  ..................................................................
...............................................................
</context>
</host>

即,来自子文件夹的 jsp include 在 http://abc.test/lang/ 并且它不适用于 http://abc.test 在这两种情况下,都可以包含同一目录中的文件

I am not able to include a jsp file from a subdirectory. I have to include a file from include subfolder to a file in the test folder.

I tried this code

<%@ include file="../../include/file.jsp"%> 

inside the file ../test/sample.jsp

But I'm getting an error like

org.apache.jasper.JasperException: /all.jsp(132,1) File "/../../include/file.jsp" not found
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:88)
org.apache.jasper.compiler.Parser.processIncludeDirective(Parser.java:300)
org.apache.jasper.compiler.Parser.parseIncludeDirective(Parser.java:333)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:442)
org.apache.jasper.compiler.Parser.parseFileDirectives(Parser.java:1749)
org.apache.jasper.compiler.Parser.parse(Parser.java:127)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:255)
org.apache.jasper.compiler.ParserController.parseDirectives(ParserController.java:120)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:180)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:347)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:326)
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)

Update: I think the problem is related to tomcat.When I used to map the root folder as context in tomcat it was working and when I add root folder as a host,the problem arises.I want to use it as a host.

Here in this tomcat config it doesn't work:

<Host name="abc.test"  appBase="c:\abcd"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">

        <Context path="/" docBase="c:\abcd" reloadable="true" crossContext="true">
 ..................................................................
...............................................................
</context>
</host>

But it works in the following config

<Host name="abc.test"  appBase="c:\abc"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">

<Context path="/lang" docBase="c:\subdir" reloadable="true" crossContext="true">
  ..................................................................
...............................................................
</context>

        <Context path="/" docBase="c:\subdir" reloadable="true" crossContext="true">
  ..................................................................
...............................................................
</context>
</host>

ie, jsp include from subfolders works in http://abc.test/lang/ and it doesn't work for http://abc.test
In both cases, the files from the same directory can be included

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

宛菡 2024-10-24 00:36:25

我发现使用完整路径信息(来自根目录)无前导斜杠似乎可以工作...

换句话说,

../../../Directory/file

我不使用:

FirstSubDir/SecondSubDir/ThirdSubDir/Directory/file

包括前导斜杠(即:/FirstSubDir/Se...)似乎会导致与所述相同的问题。

I've found using the full path info (from the root directory) sans leading slash seems to work...

In other words, instead of

../../../Directory/file

I use:

FirstSubDir/SecondSubDir/ThirdSubDir/Directory/file

Including the leading slash (ie: /FirstSubDir/Se...) seems to cause the same issue as noted.

烂柯人 2024-10-24 00:36:25

由于 include 指令采用相对路径,因此您可以从站点的根目录开始,而不是使用 ../ 语法。所以你可以尝试:/include/file.jsp。

Since the include directive takes a relative path you can start from the root of the site rather than use the ../ syntax. So you can try: /include/file.jsp.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文