Link to home
Start Free TrialLog in
Avatar of rhykker
rhykker

asked on

Unable to compile class for JSP, Cannot resolve symbol

I recently upgraded from tomcat 3.2 to tomcat 4.1.18

The problem seems to be that I used to be able to call a jsp:useBean properly.

This was working in tomcat 3.2:

=======================================
<!-- <%@ page import = "Counter" %> -->


<!-- Instantiate the Counter bean with an id of "counter" -->
<jsp:useBean id="counter" scope="session" class="Counter" />

========================================

However, now the JSP pages doesn't seem to know where the Counter.class file is.

It is in: <serverpath>/webapps/WEB-INF/classes/


I honestly do not know what changes need to be made in the JSP page to make the call to Counter.class succeed.


Does the Counter.class file need to be in a subdirectory
of classes? If not, what should the import look like since its not in a package, just in the root of classes.



I presume I need a properly defined web.xml file, however my brain is fried as I cannot seem to define it properly. This is what I tried:

========================================
<web-app>

    <servlet>
     <servlet-name>Counter</servlet-name>
     <servlet-class>Counter</servlet-class>
    </servlet>

    <servlet-mapping>
     <servlet-name>Counter</servlet-name>
     <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>
========================================
Note: I also tried:

 <url-pattern>/Counter</url-pattern>
 

This is the resulting ERROR REFERENCE:
--------------------------------------

7: '.' expected
import Counter;
              ^
/<serverpath>/webapps/PageBean_jsp.java:46: cannot resolve symbol
symbol  : class Counter
location: class org.apache.jsp.PageBean_jsp
      Counter counter = null;
      ^









Thanks.

-D
Avatar of Mick Barry
Mick Barry
Flag of Australia image

you need to include the class in a package.
objects is right, jdk1.4 requires that classes be in a package for import.




Avatar of rhykker
rhykker

ASKER

Ok,

I've add a subdirectory and the file to classes:

/classes/mypackage/Counter.class


I edited the import to:

<!-- <%@ page import = "mypackage.*" %> -->

<jsp:useBean id="counter" scope="session" class="Counter" />


However I still receive this portion of the error:


/<serverpath>/webapps/PageBean_jsp.java:46: cannot resolve symbol
symbol  : class Counter
location: class org.apache.jsp.PageBean_jsp
     Counter counter = null;
     ^


Please advise.
Avatar of rhykker

ASKER

Ok,

I've add a subdirectory and the file to classes:

/classes/mypackage/Counter.class


I edited the import to:

<!-- <%@ page import = "mypackage.*" %> -->

<jsp:useBean id="counter" scope="session" class="Counter" />


However I still receive this portion of the error:


/<serverpath>/webapps/PageBean_jsp.java:46: cannot resolve symbol
symbol  : class Counter
location: class org.apache.jsp.PageBean_jsp
     Counter counter = null;
     ^


Please advise.
just to avoid the obvious,

you've added

package mypackage

to the top of your Counter class right?
Avatar of rhykker

ASKER

Sorry about the double comment post I was trying to add the correct error message as I pasted the wrong one.


Using:
------

/classes/mypackage/Counter.class




I edited the import to:
-----------------------

<!-- <%@ page import = "mypackage.*" %> -->

<jsp:useBean id="counter" scope="session" class="Counter" />



This is the error I receive after adding the package call:
----------------------------------------------------------

/<serverpath>/webapps/PageBean_jsp.java:46: cannot access mypackage.Counter
bad class file: /<serverpath>/root/webapps/WEB-INF/classes/mypackage/Counter.class
class file contains wrong class: Counter
Please remove or make sure it appears in the correct subdirectory of the classpath.
      Counter counter = null;
      ^
1 error
Avatar of rhykker

ASKER

The obvious?

Why no I did not. Let me add that to the top of the class file and recompile to see if that fixes it.


It'll take me a few so I'll get back to you in a bit to let you know if this fixed it.

ASKER CERTIFIED SOLUTION
Avatar of bobbit31
bobbit31
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
try  
<jsp:useBean id="counter" scope="session" class="mypackage.Counter" />
Avatar of rhykker

ASKER

Ok,

bobbit31 helped me the most here. Thanks to all.



I added a subdirectory under classes called mypackage
Like so and added the Counter.class file:

/webapps/WEB-INF/classes/mypackage/Counter.class

====================================================


Then in the jsp page I added to the top of the file:

package mypackage;


====================================================


At this time I did not have to change this line:


<jsp:useBean id="counter" scope="session" class="Counter" />


====================================================


I added a web.xml file like so:

/webapps/WEB-INF/web.xml


====================================================


The contents of the web.xml file are:


<web-app>

    <servlet>
     <servlet-name>Counter</servlet-name>
     <servlet-class>mypackage.Counter</servlet-class>
    </servlet>

    <servlet-mapping>
     <servlet-name>Counter</servlet-name>
     <url-pattern>/Counter</url-pattern>
    </servlet-mapping>

</web-app>


====================================================


Thanks again and I hope this detailed result helps out someone in the future.

This was on a Tomcat 4.1.18 build.
Avatar of rhykker

ASKER

Great help and straight to the simple problem, thanks!