Reputation: 1
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
Upvotes: 0
Views: 4515
Reputation: 11
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.
Upvotes: 1
Reputation: 103135
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.
Upvotes: 0