Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP - Compile errors because of includes

 
Mike Deardorff
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a Main.jsp. This JSP defines a java variable at the top...
<% String test = "test"; %>
Inside the Main.jsp is an include file. This include file uses the test variable defined in the Main.jsp.
I am precompiling all of my JSP's. Main.jsp compiles fine, but the include file does not because test was declared in Main.jsp.
At runtime it works fine of course because the servlet engine combines the source code before compiling.
This causes a problem if you want to find errors when compiling from the jdk, or from JBuilder, or from JDeveloper. In our case, we need to deploy a war file, so "my peeps" are requiring all of the JSP's to compile first.
Suggestions?
 
Marty Hall
Author
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a Main.jsp. This JSP defines a java variable at the top...
<% String test = "test"; %>
Inside the Main.jsp is an include file. This include file uses the test variable defined in the Main.jsp.
I am precompiling all of my JSP's. Main.jsp compiles fine, but the include file does not because test was declared in Main.jsp.
At runtime it works fine of course because the servlet engine combines the source code before compiling.
This causes a problem if you want to find errors when compiling from the jdk, or from JBuilder, or from JDeveloper. In our case, we need to deploy a war file, so "my peeps" are requiring all of the JSP's to compile first.

Your included file is not a legal JSP file, and it will not compile. It is just a snippet of a JSP file. Remember:
  • If you use the jsp:include action, the two pages become separate servlets, so it makes sense to precompile them individually.
  • If you use the @include directive, the two pages are combined into one big servlet. Thus, precompilation of the included page does not make sense: after all, it will never be compiled, neither now nor at request time.


  • Maybe use a different file extension, like, say .jspf ("f" for "fragment") to indicate files that are not real JSP pages (and thus might not be able to compile separately) but just fragments to be included in other JSP pages?
    Cheers-
    - Marty
     
    vibeeshan kambli
    Ranch Hand
    Posts: 41
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You can use .inc extension ,in that way it is not included precompile list and still uses main.jsp variables
    -vishnu
     
    RAJESH RASTOGI
    Greenhorn
    Posts: 17
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    hello,
    u can use one of both include directive or jsp:include.
    <%@include file="" %>
    or
    <jsp:include page="" flush="true"/>
    include directive includes the src file at compile time.
    hope this will help u.
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic