You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Martin Lambert <ml...@globeop.com> on 2007/01/25 12:11:09 UTC

JSP include issue when pre-compiling using Ant/Tomcat

Hi,

I'm having problems doing JSP pre-compilation using Tomcat's JSP pre-compilation libraries and Ant. The problem is demonstrated by the following:

test.jsp:

<% String myVar = "Hello"; %>

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

Some more text

test2.jsp

<H1>Goodbye</H1>

<%= myVar + "World" %>

Testing

build.xml

<project default="compile-jsps">
      <target name="compile-jsps">
    	  <mkdir dir="${basedir}/build/web-test" description="creating classes directory"/>
    	  
          <taskdef classname="org.apache.jasper.JspC" name="jasper2"/>
   	  <jasper2 validateXml="false" uriroot="${basedir}/web-test" outputDir="${basedir}/build/web-test" compile="true"/>    	         	      
   	         	  
      </target>
</project>

test.jsp loads correctly when accessed from Tomcat, however, when I use Ant with the build.xml above and Tomcat's JSP compiler libraries I get:

D:\dev\myproject\build\web-test\org\apache\jsp\test2_jsp.java:43: cannot find symbol
symbol  : variable myVar
location: class org.apache.jsp.test2_jsp
      out.print( myVar + "World" );
                 ^
1 error

I have tested this using both Tomcat 5.5.15 and Tomcat 5.5.20.

When JspC completes there are 2 Java source files, test2_jsp.java which ties up with test2.jsp's content (making reference to myVar but not declaring it) and test_jsp.java which contains the combined content of test.jsp and test2.jsp. I've flagged that JspC should compile the generated source files with the compile="true" attribute, I discovered this through looking at the Javadocs.

My gut feel is that JspC should remove any Java source files that represent JSPs that cannot be run standalone, e.g. test2.jsp, as its final step before completing thus leaving only Java source files that can be compiled.

The main point of reference for doing JSP pre-compilation seems to be http://tomcat.apache.org/tomcat-5.5-doc/jasper-howto.html but it is very sparse on this subject i.e. here's a sample build.xml, it doesn't even indicate there is a compile option. Tomcat should document what attributes the JSPc task supports, just like any other Ant task.


Thanks,

Martin.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: JSP include issue when pre-compiling using Ant/Tomcat

Posted by Tim Funk <fu...@joedog.org>.
Jsp files which are compile time includes should not end in .jsp  - but 
something else. (Preferably .jspf)

renaming test2.jsp to test2.jspf will fix your precompilation issue.

Using jspf has the added advantage of also letting you know immediately 
the files being used as compile time includes. If the jsp is also not 
hidden in WEB-INF but on the document root - its also easier to protect 
those files in case a malicious user could figure out such a fragment 
exists and call it directly potentially bypassing validations or other 
logic.

-Tim

Martin Lambert wrote:
> Hi,
> 
> I'm having problems doing JSP pre-compilation using Tomcat's JSP pre-compilation libraries and Ant. The problem is demonstrated by the following:
> 
> test.jsp:
> 
> <% String myVar = "Hello"; %>
> 
> <%@ include file="test2.jsp" %>
> 
> Some more text
> 
> test2.jsp
> 
> <H1>Goodbye</H1>
> 
> <%= myVar + "World" %>
> 
<SNIP>

> 
> test.jsp loads correctly when accessed from Tomcat, however, when I use Ant with the build.xml above and Tomcat's JSP compiler libraries I get:
> 
> D:\dev\myproject\build\web-test\org\apache\jsp\test2_jsp.java:43: cannot find symbol
> symbol  : variable myVar
> location: class org.apache.jsp.test2_jsp
>       out.print( myVar + "World" );
>                  ^
> 1 error
> 
> I have tested this using both Tomcat 5.5.15 and Tomcat 5.5.20.
> 
> When JspC completes there are 2 Java source files, test2_jsp.java which ties up with test2.jsp's content (making reference to myVar but not declaring it) and test_jsp.java which contains the combined content of test.jsp and test2.jsp. I've flagged that JspC should compile the generated source files with the compile="true" attribute, I discovered this through looking at the Javadocs.
> 
> My gut feel is that JspC should remove any Java source files that represent JSPs that cannot be run standalone, e.g. test2.jsp, as its final step before completing thus leaving only Java source files that can be compiled.
> 

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org