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-I NF/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</ser vlet-name>
<servlet-class>Counter</se rvlet-clas s>
</servlet>
<servlet-mapping>
<servlet-name>Counter</ser vlet-name>
<url-pattern>/</url-patter n>
</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/Page Bean_jsp.j ava:46: cannot resolve symbol
symbol : class Counter
location: class org.apache.jsp.PageBean_js p
Counter counter = null;
^
Thanks.
-D
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-I
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</ser
<servlet-class>Counter</se
</servlet>
<servlet-mapping>
<servlet-name>Counter</ser
<url-pattern>/</url-patter
</servlet-mapping>
</web-app>
==========================
Note: I also tried:
<url-pattern>/Counter</url
This is the resulting ERROR REFERENCE:
--------------------------
7: '.' expected
import Counter;
^
/<serverpath>/webapps/Page
symbol : class Counter
location: class org.apache.jsp.PageBean_js
Counter counter = null;
^
Thanks.
-D
you need to include the class in a package.
objects is right, jdk1.4 requires that classes be in a package for import.
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/Page Bean_jsp.j ava:46: cannot resolve symbol
symbol : class Counter
location: class org.apache.jsp.PageBean_js p
Counter counter = null;
^
Please advise.
I've add a subdirectory and the file to classes:
/classes/mypackage/Counter
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/Page
symbol : class Counter
location: class org.apache.jsp.PageBean_js
Counter counter = null;
^
Please advise.
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/Page Bean_jsp.j ava:46: cannot resolve symbol
symbol : class Counter
location: class org.apache.jsp.PageBean_js p
Counter counter = null;
^
Please advise.
I've add a subdirectory and the file to classes:
/classes/mypackage/Counter
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/Page
symbol : class Counter
location: class org.apache.jsp.PageBean_js
Counter counter = null;
^
Please advise.
just to avoid the obvious,
you've added
package mypackage
to the top of your Counter class right?
you've added
package mypackage
to the top of your Counter class right?
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/Page Bean_jsp.j ava:46: cannot access mypackage.Counter
bad class file: /<serverpath>/root/webapps /WEB-INF/c lasses/myp ackage/Cou nter.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
Using:
------
/classes/mypackage/Counter
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/Page
bad class file: /<serverpath>/root/webapps
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
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try
<jsp:useBean id="counter" scope="session" class="mypackage.Counter" />
<jsp:useBean id="counter" scope="session" class="mypackage.Counter" />
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/m ypackage/C ounter.cla ss
========================== ========== ========== ======
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</ser vlet-name>
<servlet-class>mypackage.C ounter</se rvlet-clas s>
</servlet>
<servlet-mapping>
<servlet-name>Counter</ser vlet-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.
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/m
==========================
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</ser
<servlet-class>mypackage.C
</servlet>
<servlet-mapping>
<servlet-name>Counter</ser
<url-pattern>/Counter</url
</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.
ASKER
Great help and straight to the simple problem, thanks!