?
Solved

Unable to compile class for JSP, Cannot resolve symbol

Posted on 2003-02-26
11
Medium Priority
?
325 Views
Last Modified: 2013-11-24
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
0
Comment
Question by:rhykker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 92

Expert Comment

by:objects
ID: 8027949
you need to include the class in a package.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 8027968
objects is right, jdk1.4 requires that classes be in a package for import.




0
 

Author Comment

by:rhykker
ID: 8027997
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rhykker
ID: 8028048
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.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 8028069
just to avoid the obvious,

you've added

package mypackage

to the top of your Counter class right?
0
 

Author Comment

by:rhykker
ID: 8028106
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
0
 

Author Comment

by:rhykker
ID: 8028137
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.

0
 
LVL 18

Accepted Solution

by:
bobbit31 earned 200 total points
ID: 8028203
don't forget to add a semi-colon:

package mypackage;

0
 
LVL 28

Expert Comment

by:rrz
ID: 8030303
try  
<jsp:useBean id="counter" scope="session" class="mypackage.Counter" />
0
 

Author Comment

by:rhykker
ID: 8031058
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.
0
 

Author Comment

by:rhykker
ID: 8031095
Great help and straight to the simple problem, thanks!
0

Featured Post

Quick Start: DOCKER

Sometimes you just need a Quick Start on a topic in order to begin using it.. this is just what you need to know to get up and running with Docker!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question