2

I want to ask a question about the JSP page. I set the project in the following structure in order to manage the project efficiently. When I am in the list folder, main.jsp, I set the header as the following

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

When I open the main.jsp, It shows the error

cannot find the "jsp/list/universe/header.jsp"

the header.jsp and other classes cannot be read. Can anyone help me to solve the problem? thank you.

Class structure

webapp
|
|-- jsp
    |
    |-- list
    |   |
    |   |--main.jsp
    | 
    |-- universe
        |
        |-- header.jsp
        |-- footer.jsp
bluish
  • 26,356
  • 27
  • 122
  • 180
Questions
  • 20,055
  • 29
  • 72
  • 101
  • 2
    From your structure, it appears universe is under jsp/, not jsp/list/ as in the error message -- If I'm reading it correctly, then file="../universe/header.jsp" might work? – belwood Oct 07 '10 at 04:48

3 Answers3

5

In a JSP include directive the path can be relative to the including page or absolute (then it has to start with a / and belongs to the webapplication root directory).

So in this case you have to set the path either to ../universe/header.jsp or /jsp/universe/header.jsp.

vanje
  • 10,180
  • 2
  • 31
  • 47
0

In JSP include directive, path can be relative.

You can use it this way

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

You can refer the directives on many sites. Best one is sun java website.

Or you can visit this page Include Directive

Vivek
  • 1,640
  • 1
  • 17
  • 34
-1

It depends if your using the classpath to locate files. if your using classpath to locate your files then it should be inside your class folder

Jono
  • 17,341
  • 48
  • 135
  • 217
  • Sorry, but this is not true for JSP files in a web application. Here JSP files are not only simple resource files to locate. A web application in the JEE context has a defined structure. Look at http://www.jsptube.com/servlet-tutorials/web-application-directory-structure.html Usually the /WEB-INF/classes and the JARs in /WEB-INF/lib are in the classpath and JSP files resides always outside of these folders. – vanje Oct 07 '10 at 05:43