5 Replies Latest reply on Feb 16, 2006 3:06 PM by j2ee_junkie

    Can not use Generics in JSP

    danielywoo

      Hi,

      I can not use generics in JSP, for example:

      <%
       List<User> list = new ArrayList<User>(1000);
       for (int i = 0; i < 1000; i++) {
       User u = new User("test" + i, i);
       list.add(u);
       }
       test.insertAllUserList(list);
       %>

      The console shows strace:

      11:53:16,546 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
      org.apache.jasper.JasperException: Unable to compile class for JSP
      An error occurred at line: 4 in the jsp file: /test_slsb_entity_insert.jsp
      Generated servlet error:
      Syntax error on token "<", invalid AssignmentOperator
      An error occurred at line: 4 in the jsp file: /test_slsb_entity_insert.jsp
      Generated servlet error:
      Syntax error on token "=", != expected
      An error occurred at line: 4 in the jsp file: /test_slsb_entity_insert.jsp
      Generated servlet error:
      Syntax error on token "new", delete this token


        • 1. Re: Can not use Generics in JSP
          danielywoo

          Does anybody know the behavior of tomcat jsp compiler? Why it doesnot support JDK5.0 features like generics?

          • 2. Re: Can not use Generics in JSP
            danielywoo

            I found the reason.
            delete jdt compiler and copy ant.jar, tools.jar to tomcat.sar/conf
            set compiler to 1.5 in default web.xml

            • 3. Re: Can not use Generics in JSP
              nikolaymetchev

              This issue is duscussed in the Wiki:
              http://wiki.jboss.org/wiki/Wiki.jsp?page=402UpgradeIssues
              However I haven't been able to find out why the JDT compiler cannot be used for compiling Java 5 code. Is there a JIRA/Bugzilla issue to do with this?

              • 4. Re: Can not use Generics in JSP
                p_saville1

                JBoss IDE or Eclipse WTP, not sure which is doing my JSP compilation... But in the problems tab, all my JAVA 5.0 Generics code in JSPs show errors.

                I am using Tomcat 5, and the JSPs compile and run fine in Tomcat... Just my IDE errors list is filling up with Generics errors in JSPs.

                Is there a way to fix this?

                • 5. Re: Can not use Generics in JSP
                  j2ee_junkie

                  What I did to solve this issue was to specify which JSP compiler to use in my web.xml file.

                  <web-app>
                  ...
                   <!-- specify jsp's compiler and java 1.5 standard -->
                   <servlet>
                   <servlet-name>jsp</servlet-name>
                   <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
                   <init-param>
                   <param-name>compilerSourceVM</param-name>
                   <param-value>1.5</param-value>
                   </init-param>
                   <init-param>
                   <param-name>compilerTargetVM</param-name>
                   <param-value>1.5</param-value>
                   </init-param>
                  
                   <init-param>
                   <param-name>fork</param-name>
                   <param-value>false</param-value>
                   </init-param>
                   <init-param>
                   <param-name>xpoweredBy</param-name>
                   <param-value>false</param-value>
                   </init-param>
                   <load-on-startup>3</load-on-startup>
                   </servlet>
                  ...
                   <!-- The mapping for the JSP servlet -->
                   <servlet-mapping>
                   <servlet-name>jsp</servlet-name>
                   <url-pattern>*.jsp</url-pattern>
                   </servlet-mapping>
                  ...
                  </web-app>
                  


                  enjoy, cgriffith