With the split of the groups, the original message I posted is called 'JSP's and class files.....' Here's the link: http://www.javaranch.com/ubb/Forum7/HTML/006589.html Thanks for the response... but it has led to a few more questions!! You mentioned that "Once the JSP can see the classes...", well if I were to follow your suggestions, my JSPs still cant load the class files. Could this be a problem with the directory structure?? Here's what I have. The path to my tomcat directory is: C:\Tomcat\webapps\work the class sits in this directory: C:\Tomcat\webapps\work\WEB_INF\classes I have a class that is called stone.class My useBean tag goes something like this: <jsp:useBean id="StonesBean" class="stone.class" scope="application" /> Upon typing in "http://localhost:8080/work/jsp/index.htm", (the jsp is in a frame...) I get an error that says "org.apache.jasper.JasperException: Unable to load class stone.class". I've tried many variations of my useBean call, but none have worked. I've adjusted my java code so it now contains an appropriate constructor. Am I on the right track?? or way off?? Any suggestions?? Oh yeah, and performing a shutdown and restart doesn't seem to help. Thanks, Stone
Carl Trusiak
Sheriff
Joined: Jun 13, 2000
Posts: 3340
posted
0
<jsp:useBean id="StonesBean" class="stone.class" scope="application" /> When refering to a class file, you do not need the .class extention. Java thinks this is a class called class in the stone package. Change this to <jsp:useBean id="StonesBean" class="stone" scope="application" />
Stone, JavaRanch has a Naming Policy please read and follow it.
Stone_Golem
Greenhorn
Joined: Oct 21, 2001
Posts: 2
posted
0
Thanks for the reply..... Unfortunately, this hasn't helped much as it still does not work. Does anyone have any suggestions before I sell my computer?? Does anyone know of a step by step tutorial or a published example of the situation that is similar to mine?? Thanks, Stone BTW, I'll swicth my name when this problem is solved... I hope that's okay!!
Carl Trusiak
Sheriff
Joined: Jun 13, 2000
Posts: 3340
posted
0
I recall hearing of a problem with Tomcat and JSP Beans that are not in packages. Put your class stone in a package such as beans. Put the compiled class file under /WEB-INF/classes/beans/ and change your tage to <jsp:useBean id="StonesBean" class="beans.stone" scope="application" />
Francois Bourgault
Ranch Hand
Joined: Oct 30, 2001
Posts: 67
posted
0
Hi, I'm also having the same problem. Just want to know if you guys found a solution to the problem. I'll keep looking at it and let you know if I find how to make it work. Francois.
Madhav Lakkapragada
Ranch Hand
Joined: Jun 03, 2000
Posts: 5040
posted
0
Did you import the class file stone in your JSP? Also what version of Tomcat are you using? regds. - satya ps: Determined to make you change your name.
Yeah.... What I did was I created a package. I did this by adding the line 'package myPackage;' and then I placed the files in a directory called myPackage. See Carl Trusiak's post on how to access them... I also made my classes public.... that's one of those things that will drive you crazy for hours.... I also made sure that my CLASSPATH and PATH were set properly. Hope this helps.... Stone
Stone Golem
Greenhorn
Joined: Oct 27, 2001
Posts: 8
posted
0
Madhav, nope... no import was needed.... just declared the bean, and accessed it! Stone
Madhav Lakkapragada
Ranch Hand
Joined: Jun 03, 2000
Posts: 5040
posted
0
Yes, no import is necessary. I just wrote an app myself and verified. And I din't need any package. It worked for me with Tomcat 3.2.1 In case you are interested heres' the code:
Thanks for changing your name. regds. - satya
Francois Bourgault
Ranch Hand
Joined: Oct 30, 2001
Posts: 67
posted
0
Hi all, I moved my code from tomcat 3.2(everything was working, including beans) to tomcat 4.0.1 Now I'm also getting "bean not found". I created a folder web-inf\classes\Beans and put the class there. I updated my classpath/path. In my jsp page, I do the following: <jsp:useBean id="formhandler" class="Beans.Guest_Bean" scope="session"/> Are you guys also using tomcat 4.0.1? Di you make it work using tomcat 4.0.1? Any solution to that problem? I'll keep looking at it and if I make it work, I'll let you know. Francois.
Madhav Lakkapragada
Ranch Hand
Joined: Jun 03, 2000
Posts: 5040
posted
0
moved my code from tomcat 3.2(everything was working, including beans) to tomcat 4.0.1 Now I'm also getting "bean not found". I created a folder web-inf\classes\Beans and put the class there. I updated my classpath/path. In my jsp page, I do the following: <jsp:useBean id="formhandler" class="Beans.Guest_Bean" scope="session"/> In this case did you define a package stmt in your Guest_Bean java code. I was using 3.2.1 in the above example. regds. - satya
Francois Bourgault
Ranch Hand
Joined: Oct 30, 2001
Posts: 67
posted
0
Madhav, Yes I added the package stmt. Below is the error I get when I call the jsp page: An error occurred at line: 21 in the jsp file: /list_guests.jsp Generated servlet error: C:\Apache\jakarta-tomcat\work\localhost\Src\list_0005fguests$jsp.java:86: Class Beans.Guest_Bean not found. formhandler= (Beans.Guest_Bean) As you can see, the system can't find the bean. The structure is as follow: web-inf\classes\Beans\Guest_Bean.class Not sure why the system can't find the class file. Francois
Madhav Lakkapragada
Ranch Hand
Joined: Jun 03, 2000
Posts: 5040
posted
0
Generated servlet error: C:\Apache\jakarta-tomcat\work\localhost\Src\list_0005fguests$jsp.java:86: Class Beans.Guest_Bean not found. formhandler= (Beans.Guest_Bean)
Are you trying to cast something (to Beans.Guest_Bean) in the last stmt above? Could you pl. post the relavent JSP stmt, so we can take a look. regds. - satya
Francois Bourgault
Ranch Hand
Joined: Oct 30, 2001
Posts: 67
posted
0
Here's the jsp line: <jsp:useBean id="formhandler" class="Beans.Guest_Bean" scope="session"/> As a test, I also created a c:\Beans\Guest_Bean.class and added it to my classpath and path. Still it doesn't work. All html/jsp files are in: webapps\Src and classes are in: webapps\myServlets\web-inf\classes
Francois Bourgault
Ranch Hand
Joined: Oct 30, 2001
Posts: 67
posted
0
Something else. jsp line: <%@ page language="java" import="java.sql.*, Beans.*" %> When I run the jsp, I get: org.apache.jasper.JasperException: Unable to compile class for JSP C:\Apache\jakarta-tomcat\work\localhost\Src\list_0005fguests$jsp.java:4: Package Beans not found in import. import Beans.*; I have a c:\Beans defined in classpath and path. Do I have to update web.xml or server.xml with the location of the file?
Madhav Lakkapragada
Ranch Hand
Joined: Jun 03, 2000
Posts: 5040
posted
0
I have a c:\Beans defined in classpath and path. Personally I don't think its a good idea to hack the CLASSPATH. Tomcat sets its own CLASSPATH. If you have the jars/class files in the right place under your application, till now I have never faced any problems. So I am not a big fan of modifying the CLASSPATH. I personally wouldn't go that route... Having said that, the line I was asking was the line in your JSP which had: formhandler= (Beans.Guest_Bean) or was this in the generated java code.
- satya
Francois Bourgault
Ranch Hand
Joined: Oct 30, 2001
Posts: 67
posted
0
It is generated java code. In tomcat 3.2, I have beans in web-inf\classes and it works. If I do the same in tomcat 4.0.1 , this is what I get: Generated servlet error: C:\Apache\jakarta-tomcat\work\localhost\Src\list_0005fguests$jsp.java:83: Class org.apache.jsp.Guest_Bean not found. Guest_Bean formhandler = null;
Look at the package: org.apache.jsp.Guest_Bean That's why I created a different subdirectory and updated the classpath
It's because you are using your Guest_Bean 'naked' (Guest_Bean formhandler = null; ) in the body of your JSP, so Tomcat will try to append 'org.apache.jsp.' and try to resolve it this way.
Tomcat 3.2.x used the System classpath, but 4.0.1 does NOT. This is one big difference I noticed. So setting your CLASSPATH in 4.0.1 won't help a bit.
To be certain: In 4.0.1, your JSP includes an import directive for the bean classes, the classes reside in your WEB-INF/classes folder, you use (if any) full package names in the jsp:useBean tag, and the JSP still won't compile? Don't use the bean class directly like that, use it through the tags. [This message has been edited by Mike Curwen (edited November 03, 2001).]
Francois Bourgault
Ranch Hand
Joined: Oct 30, 2001
Posts: 67
posted
0
Mike, The code "Guest_Bean formhandler = null;" is part of the error message(Generated servlet error) I get when I run the jsp. This line isn't in the jsp file. Below is the tag I use in the jsp page: <jsp:useBean id="formhandler" class="Guest_Bean" scope="session" /> and the class is in web-inf\classes. When I run it like that, tomcat add "org.apache.jsp." to the class and I get an error that "Class org.apache.jsp.Guest_Bean not found". When I specify a package(Beans.Guest_Bean) tomcat can't find the package. Not sure what's going on here! The file structure is like this: All html/jsp files are in: webapps\Src and classes are in: webapps\myServlets\web-inf\classes I will reinstall tomcat in a different directory and copy all files in: webapps\examples\servlets\classes and see if I can make it work. If you think I'm missing something, let me know What I'm trying to do is to have the code outside the examples directory(that was the structure I used in tomcat 3.2) so I created myServlets directory and copy all files/folders from examples to myServlets folder and run the application using that folder. Thanks for your help. Francois.