14 Replies Latest reply on Nov 19, 2012 5:39 AM by thavaselvan

    JSP Compiler : cannot be resolved to a type

    ejb3workshop

      Since upgrading form Jboss 4.2.3 to 5.1 I am no longer able to access the JSP pages

       

      In the header.jsp included via prelude in web.xml I am inluding the menu jsp fragment:

       

      <%@page contentType="text/html; charset=utf-8"%>
      <%@page pageEncoding="UTF-8"%>
      <%@page import="java.util.*"%>
      <jsp:useBean id="now" class="java.util.Date"/>
      
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
      <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
      </head>
      <body>
      <%@include file="menu.jspf"%>
      ...
      </body>
      </html>
      

       

       

      And then in menu.jspf

       

      <%@page import="java.util.*" %><%
          Map<String, String> menuItems = new LinkedHashMap<String, String>();
      ...
      

       

      In both files I am inporting the java.util package, however after deployment when I access the page I get the following compilation error

      An error occurred at line: 3 in the jsp file: /menu.jspf

      Map cannot be resolved to a type

      1: <%@page import="java.util.*" %>

      2: <%

      3:     Map<String, String> menuItems = new LinkedHashMap<String, String>();

      I am alos getting other errors that it cant resolve some of my own classed. I tried to fix those by setting the classpath inside the MANIFEST file of my web applications included in the application EAR.

       

      EAR:

      ->WAR1:

      -->META-INF/MANIFEST (Contains Class-Path : JAR1)

      ->WAR2:

      -->META-INF/MANIFEST (Contains Class-Path : JAR1)

      ->JAR:1

      -/lib/THIRD_PARTY_LIB1.JAR

      -/lib/THIRD_PARTY_LIB2.JAR

      -/lib/THIRD_PARTY_LIB3.JAR

       

      However since it can't resolve standard java classes like Map, LinkedHashMap and Enumeration I am rather confused as to why this is happening or how I can fix this. I am using JDK 1.5 and JBoss 5.1 GA. I am deploying my EAR to the farm folder.

       

      Any suggestion greatly appreciated.

        • 1. Re: JSP Compiler : cannot be resolved to a type
          jaikiran

          Is this Windows OS?

          • 2. Re: JSP Compiler : cannot be resolved to a type
            ejb3workshop

            Yes. Windows 64 bit.

            • 3. Re: JSP Compiler : cannot be resolved to a type
              jaikiran
              • 4. Re: JSP Compiler : cannot be resolved to a type
                ejb3workshop

                Looks like a differnt issue. Mine is with standard Java classes.

                • 5. Re: JSP Compiler : cannot be resolved to a type
                  ejb3workshop

                  I made some progress on this issue, however I am not convinced that this is the best solution, nor why this only happens with JBoss 5.1 and not JBoss 4.2.3 or other application server.

                   

                  My web application consists of the following components:

                   

                  1.) header.jspf

                  <%@page contentType="text/html; charset=utf-8"%>
                  <%@page pageEncoding="UTF-8"%>
                  <%@page import="java.util.*"%>
                  <%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
                  <%@taglib prefix="core" uri="http://java.sun.com/jsp/jstl/core" %>
                  <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
                  
                  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
                  <head>
                    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
                    <title>The Title</title>
                  </head>
                  <body>
                              <%@include file="menu.jspf"%>
                  

                   

                  2.) footer.jspf

                  </body>
                  </html>
                  

                   

                  3.) menu.jspf

                  <%@page import="java.util.*" %>
                  <%
                      Map<String, String> menuItems = new LinkedHashMap<String, String>();
                  ...
                  %>
                  ...
                  

                   

                  4.) Many other pages which obtain the header and footer via prelude and code defined in web.xml.

                  <div>   
                       Some JSP page
                  </div>

                   

                  This worked great in JBoss 4.2.3 however in JBoss 5.1 it stopped working. For some reason the JSP compiler was no longer able to combine all the various import statements correctly. What I had to do to get it working in 5.1 was to add all the required import statements in each JSP page, even though none of them were directly used in the page itself, but only in the related pages

                   

                  4.) A simple page fixed for 5.1 with import statement

                  <%@page import="java.util.*"%>
                  <div>   
                       Some JSP page
                  </div>
                  

                   

                  I am not sure if it worked in 4.2.3 due to a loose interpretation of the specification, however this method also worked on other application servers, with 5.1 being the exception. Previously the import in the header page seem sufficient to apply to all pages to which the header was applicable.

                   

                  I would be most grateful for any insight into this matter and possible alternative solutions.

                  • 6. Re: JSP Compiler : cannot be resolved to a type
                    ejb3workshop

                    I created a simple application to illustrate the problem.

                     

                    The Working.war file specified the page imports on the index.jsp page while the Defective.war specifies the imports on the included header page.

                     

                    The following error is reported with the defective application:

                     

                    An error occurred at line: 13 in the jsp file: /header.jspf
                    Map cannot be resolved to a type
                    10:   <body>
                    11:     <h1>Header</h1>
                    12:     <%
                    13:       Map map = new HashMap();
                    14:       map.put("A", "A");      
                    15:       map.put("B", "B");      
                    16:       map.put("C", "C");
                    

                     

                    I had a look a the JSP specification (jsp-2_1-fr-spec.pdf) and found the following under the page import directive:

                    Page authors may use the include-prelude feature (see Section JSP.3.3.5, “Defining Implicit Includes”) in order to have additional packages imported transparently into their pages.

                    This seems to suggest that what I am trying to do is directly supported by the specification, even though I have to admit it is not very clearly worded.

                     

                    I also tested this with JBoss 6 and JBoss 5.1 EAP and did not encounter this issue.

                     

                    Appreciate any input in this issue.

                    • 7. Re: JSP Compiler : cannot be resolved to a type
                      jfclere

                      Hm this has been fixed in jbossweb. Update the jbossweb.jar to the latest that will fix the problem.

                      • 8. Re: JSP Compiler : cannot be resolved to a type
                        ejb3workshop

                        Thanks. Where do I get this jar (jbossweb.jar) from ? I downloaded https://repository.jboss.org/nexus/content/repositories/releases/jboss/web/jbossweb/ and replaced the jbossweb.jar with jbossweb-2.1.7.GA.jar. This resolved my problem.

                        • 9. Re: JSP Compiler : cannot be resolved to a type
                          jaikiran

                          By the way, why not just upgrade to JBoss AS 6.0.0.Final, which I guess probably already has this fix?

                          • 10. Re: JSP Compiler : cannot be resolved to a type
                            thavaselvan

                            I replaced jbossweb.jar with jbossweb-2.1.7.GA.jar still I am getting the same error in jboss-5.1.0.GA server

                            • 11. Re: JSP Compiler : cannot be resolved to a type
                              jfclere

                              the guess is that you:

                              1 - didn't remove the old one.

                              2 - didn't put it in the right profile.

                              • 12. Re: JSP Compiler : cannot be resolved to a type
                                thavaselvan

                                1 - our application deployed in server/default/deploy

                                2 - I replaced jbossweb.jar with jbossweb-2.1.7.GA.jar in server/default/deploy

                                3 - nohup log  changes get reflected ->  Starting Servlet Engine: JBoss Web/2.1.7.GA

                                4 - still getting the same error

                                An error occurred at line: 2,477 in the jsp file: /jsp/CustomerView.jsp

                                Vector cannot be resolved to a type

                                2477:                               Vector lv_kwg18_con = customer.getkwg18_conf();

                                2478:                               for(int k1=0;k1<lv_kwg18_con.size();k1+=2)

                                 

                                5. Note Its working fine in weblogic server, without importing java.util.* package.

                                6. If I import java.util.*, then its working fine.

                                7. any way to solve this issue without importing util package in jsp in JBOSS 5.2 server.


                                • 13. Re: JSP Compiler : cannot be resolved to a type
                                  jfclere

                                  7 No.

                                   

                                  The problem is that weblogic server incorrectly import java.util.* (According the specs it shouldn't).

                                  • 14. Re: JSP Compiler : cannot be resolved to a type
                                    thavaselvan

                                    thanks Jean