2 Replies Latest reply on Mar 9, 2009 12:23 PM by Peter Johnson

    JSP build problem with JBoss AS 5.0.x

    Rainer Meier Newbie

      Hi all,

      I am quite new to web development and run into problems using JBoss AS 5.0.x.

      It seems that JBoss Web is not building the servlet class correctly when generating servlets from JSP. According to the specification it is allowed to put page directives at any location within a JSP (or its statically included files). Unfortunately it looks like JBoss 5 is not adding these includes to the header of the generated _jsp.java and therefore is unable to compile it.

      A simple example:

      WebContent/index.jsp:

      <h1>Hello World</h1>


      WebContent/WEB-INF/includes/header.jspf
      <%@ page import='java.util.Vector'%>
      
      <html>
      <head>
      <title>Test</title>
      </head>
      <body>
      <p>
      <%! boolean test=true; %>
      <%
       Vector v = new Vector();
       v.add(new Integer(2));
      %>
      Value: <%= v.get(0).toString() %>
      </p>


      WebContent/WEB-INF/includes/footer.jspf
      </body>
      </html>


      WebContent/WEB-INF/web.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
       id="WebApp_ID" version="2.5">
       <display-name>Test</display-name>
      
       <jsp-config>
       <jsp-property-group>
       <display-name>Test</display-name>
       <url-pattern>/index.jsp</url-pattern>
       <include-prelude>/WEB-INF/includes/header.jspf</include-prelude>
       <include-coda>/WEB-INF/includes/footer.jspf</include-coda>
       </jsp-property-group>
       </jsp-config>
      </web-app>



      So far so good. Now I run the code (packed to a .war file) on JBoss 5.0.1.GA-jdk6. As soon as I access index.jsp JBoss starts to compile it. Unfortunately it terminates with the following exception:

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
       id="WebApp_ID" version="2.5">
       <display-name>Test</display-name>
      
       <jsp-config>
       <jsp-property-group>
       <display-name>Test</display-name>
       <url-pattern>/index.jsp</url-pattern>
       <include-prelude>/WEB-INF/includes/header.jspf</include-prelude>
       <include-coda>/WEB-INF/includes/footer.jspf</include-coda>
       </jsp-property-group>
       </jsp-config>
      </web-app>


      So it seems to be unable to locate the "Vector" class which is imported within the header.

      Looking at the generated index_jsp.java file reveals the following:

      package org.apache.jsp;
      
      import javax.servlet.*;
      import javax.servlet.http.*;
      import javax.servlet.jsp.*;
      
      public final class index_jsp extends org.apache.jasper.runtime.HttpJspBase
       implements org.apache.jasper.runtime.JspSourceDependent {
      
       boolean test=true;
       private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();
      
       private static java.util.List _jspx_dependants;
      
       static {
       _jspx_dependants = new java.util.ArrayList(2);
       _jspx_dependants.add("/WEB-INF/includes/header.jspf");
       _jspx_dependants.add("/WEB-INF/includes/footer.jspf");
       }
      ...


      As you can see the class variable "test" of type boolean has been inserted but not the include.

      I did not manage yet to find a work-around to this problem.

      I tried JBoss 5.0.0.GA and 5.0.1.GA (both "normal" and "jdk6" editions). The same code runs perfectly on JBoss 4.2.3.
      The code also works Tomcat 6.0.18.


      As I am new to JBoss development somebody might point me the right direction to solve the problem or confirm that it is a bug.

      Work-arounds or tryout versions of JBoss-Web are welcome too.

        • 1. Re: JSP build problem with JBoss AS 5.0.x
          Rainer Meier Newbie

          I am sorry, I wrongly pasted the content of web.xml twice and therefore the stack trace was missing. So here's the stack trace I receive on JBoss AS 5.0.1.GA:

          22:28:18,179 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
          org.apache.jasper.JasperException: Unable to compile class for JSP:
          
          An error occurred at line: 11 in the jsp file: /WEB-INF/includes/header.jspf
          Vector cannot be resolved to a type
          8: <p>
          9: <%! boolean test=true; %>
          10: <%
          11: Vector v = new Vector();
          12: v.add(new Integer(2));
          13: %>
          14: Value: <%= v.get(0).toString() %>
          
          
          An error occurred at line: 11 in the jsp file: /WEB-INF/includes/header.jspf
          Vector cannot be resolved to a type
          8: <p>
          9: <%! boolean test=true; %>
          10: <%
          11: Vector v = new Vector();
          12: v.add(new Integer(2));
          13: %>
          14: Value: <%= v.get(0).toString() %>
          
          
          Stacktrace:
           at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
           at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
           at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
           at org.apache.jasper.compiler.Compiler.compile(Compiler.java:335)
           at org.apache.jasper.compiler.Compiler.compile(Compiler.java:313)
           at org.apache.jasper.compiler.Compiler.compile(Compiler.java:300)
           at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:585)
           at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:312)
           at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)
           at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
           at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
           at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
           at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
           at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
           at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
           at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
           at java.lang.Thread.run(Thread.java:619)


          • 2. Re: JSP build problem with JBoss AS 5.0.x
            Peter Johnson Master

            You might want to post a query in the JBossAS5 forum, providing a link to this topic. That forum is the best place to get answers to why things that worked previously are no longer working in AS 5.

            Personally, I avoid scriptlets (server-side script) within my JSPs.