Masaoud wrote:
>
> Hi,
>
> I am new to JSP's and Beans. I have written a Java class which acceses a
> MySQL database on a remote machine usingd JDBC. This class when run
> using the java interpreter works fine and displays proper results.
>
> Now, I converted the above class file into a bean, by creating a ".jar"
> file and updated the manifest file accordingly. I am using the trial
> Java Web Server 2.0, so I placed the ".jar" file in the "lib" directory
> of the Java Web Server, and restarted the web server.
>
> I have a JSP file which uses the above mentioned class as a bean. When I
> try to access it, it gives me the following error :
> " javax.servlet.ServletException : Cannot create bean of class
> abc.dbclass "
>
> In the above message "dbclass" is my bean class, whereas abc is the
> folder containig that class when the ".jar" file was created.
>
> All the JDBC drivers that are required, have also been placed in the
> appropriate directory hierrarchy.
>
> Just to doble check I tried writting a very simple bean which just had a
> method that displayed a message. When I ran the JSP with this particular
> bean, it worked fine.
>
> I want to know that are there any particular things that are not to be
> performed in a bean, or which don't work in a bean, or any special care
> to be taken while writting a bean which uses JDBC. Or any other area
> which I may have overlooked.
>
> Also supplement your answer with some examples, if possible.
A bean is just a Java class, with no restrictions whatsoever. It seems like you
need to look at how packages work.
The fully qualified name of a class is composed of the package name plus
the class name. In your example it seems like you have a class named "dbclass"
in a package named "abc", or at least that's what you have specified in the
useBean tag. This works fine if you:
1) Specify the package name in your source file, i.e.
package abc;
public class dbclass {
...
}
2) Put the .class file in a subdirectory to a directory in the CLASSPATH with
the same name as the package. For JWS I believe the <JWS>/classes directory
is included in the CLASSPATH automatically, so you can place it in
<JWS>/classes/abc
3) If you rather use a JAR file, you must use the same kind of structure in
the JAR file as in the file system, i.e. the .class file must be in a
subdirectory with the same name as the package. But while you're developing
the class it's usually easier to just put it in the classes directory as
in 2) above.
4) In your JSP page, specify the fully qualified name for the class, i.e.
<jsp:useBean id="myDb" class="abc.dbclass" />
--
Hans Bergsten [EMAIL PROTECTED]
Gefion Software http://www.gefionsoftware.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html