0

I'm trying to pre-compile .jsp files just as a way to check for errors but the issue is that despite syntax errors in the .jsp file, the .class file is still successfully generated and no errors occur when precompiling using Ant.

I am using Tomcat's JSPC task.

<taskdef classname="org.apache.jasper.JspC" name="jasper" >
      <classpath refid="myjars"/>
</taskdef>

<!--I also tried using it with compiler="org.eclipse.jdt.core.JDTCompilerAdapter"-->

<jasper 
      uriroot="WebContent" 
      outputDir="GenWebContent" />

However, if I deploy the application to Tomcat and go to the link (http://localhost/app/page.jsp?jsp_precompile=true) which also precompiles the JSP without running it, I actually do get an error regarding compiling the file.

org.apache.jasper.JasperException: Unable to compile class for JSP: 
Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:102)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:212)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:552)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:381)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:351)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:335)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:597)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:399)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    com.imedris.Utilities_Charset_Filter.doFilter(Utilities_Charset_Filter.java:25)
    com.imedris.ClickjackFilter.doFilter(ClickjackFilter.java:31)
    com.imedris.XssFilter.doFilter(XssFilter.java:182)
    com.imedris.LocaleFilter.doFilter(LocaleFilter.java:24)

How can I get the same error I get by visiting the link as I do by building through Ant? Why does it successfully compile the JSP in Ant, despite the intentional syntax errors I introduced?

Any help or suggestions would be very appreciated. Thank you.

Essam Al-Mansouri
  • 1,049
  • 2
  • 11
  • 19

1 Answers1

0

Apparently I had misunderstood what JspC was doing. I incorrectly assumed that it was compiling the .jsp files down to bytecode, when it was actually generating .java files that I still needed to compile in another step.

Compiling the generated java file with the syntax error I had introduced did result in an error as expected.

One thing to note though is that now I actually compile .java files twice, the first time I'm compiling the regular java files and placing the generated .class files in the /WEB-INF/classes folder, then generating java files from the jsp files (which doesn't work for me unless I have the .class files from first step), then compiling all the java files altogether in the third step. I'm sure that's not the optimal way to do it but I guess that's a problem for another day.

Essam Al-Mansouri
  • 1,049
  • 2
  • 11
  • 19