aspose file tools*
The moose likes JSP and the fly likes JSP - Compile errors because of includes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP - Compile errors because of includes" Watch "JSP - Compile errors because of includes" New topic
Author

JSP - Compile errors because of includes

Mike Deardorff
Greenhorn

Joined: Jan 22, 2003
Posts: 1
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

Joined: Jan 02, 2003
Posts: 111
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


    Java training and consulting
    vibeeshan kambli
    Ranch Hand

    Joined: Jan 22, 2003
    Posts: 41
    You can use .inc extension ,in that way it is not included precompile list and still uses main.jsp variables
    -vishnu
    RAJESH RASTOGI
    Greenhorn

    Joined: Jan 20, 2002
    Posts: 17
    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.
     
     
    subject: JSP - Compile errors because of includes