Solved

using a javabean in JSP....where???

Posted on 2002-06-26
31
273 Views
Last Modified: 2010-08-05
Here is what I have:
Tomcat 4.0
JDK 1.4
W2000 Server

I'm trying to use javabeans with my JSP page. I have successfully created a javabean class file and have put it in the /WEB_INF/classes folder in the directory where the jsp files are located. To access the javabean I used this tag:

<jsp:useBean class="insertBean" id="insert" scope="application" />

I have also tried..

<jsp:useBean class="/classes/insertBean" id="insert" scope="application" />

but when I try to load the page I get an error saying that it cannot find insertBean.class

Where should I put the class file?
0
Comment
Question by:ltdang7
  • 15
  • 14
  • +1
31 Comments
 
LVL 92

Expert Comment

by:objects
ID: 7112641
Is your bean in a package?
The WEB-INF directory needs to be in the basae directory of the webapp.
0
 
LVL 1

Author Comment

by:ltdang7
ID: 7113573
NO it's not, this is my directory info


ROOT
    |-- WEB-INF  [web.xml]
    |   |-- classes  insertbean.class
    |   `-- lib  
    |
    `jsp files
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7113599
are you importing the bean? does it have a package associated with it?

when you have the usebean try putting the full package name.

CJ
0
 
LVL 1

Author Comment

by:ltdang7
ID: 7113764
It is not in a package, I have got the file insertBean.class alone in the classes folder.
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7113787
rather than useBean can you try this:

<%
  insertBean myInserBean = new insertBean();

%>

and see what happens.
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7113794
also, is the file name insertBean or InsertBean

CJ
0
 
LVL 1

Author Comment

by:ltdang7
ID: 7113919
It is insertBean.call and this is what I got when I tried..
<%
 insertBean myInserBean = new insertBean();

%>

I got this>>>

Generated servlet error:
C:\Program Files\Apache Tomcat 4.0\work\localhost\_\beans$jsp.java:60: Class org.apache.jsp.insertBean not found.
                 insertBean myInserBean = new insertBean();
0
 
LVL 1

Author Comment

by:ltdang7
ID: 7113992
It is insertBean.call and this is what I got when I tried..
<%
 insertBean myInserBean = new insertBean();

%>

I got this>>>

Generated servlet error:
C:\Program Files\Apache Tomcat 4.0\work\localhost\_\beans$jsp.java:60: Class org.apache.jsp.insertBean not found.
                 insertBean myInserBean = new insertBean();
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7114076
few things to note here:

first make sure that your beans class is public meaning it is declared as:
public class insertBean

Another issue might be namespace.  Supposedly some engines (maybe Tomcat falls in this category) do not handle unnamed packages (classes not in any package) well so classes end up not being found.  You can solve this by having a package name for your class.

CJ

0
 
LVL 27

Expert Comment

by:rrz
ID: 7114283
>C:\Program Files\Apache Tomcat 4.0\work\localhost\_\beans$jsp.java:60: Class org.apache.jsp.insertBean not found.

Yes, as CJ says, put your bean in a package. Tomcat thinks the bean is in the org.apache.jsp  package.
0
 
LVL 1

Author Comment

by:ltdang7
ID: 7114939
Thanks guys...

>>first make sure that your beans class is public meaning >>it is declared as:
>>public class insertBean
I have check that and it is public

>>Yes, as CJ says, put your bean in a package. Tomcat >>thinks the bean is in the org.apache.jsp  package.
Can I use Winzip to make a jar file? Where do I out this package once I have created it?
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7114950
if your package is
ltdang
and your class is insertBean

you reference it using ltdang.insertBean

and you put the ltdang.class file in
/WEB-INF/classes/ltdang/

or you can jar it up.

to jar it up you need to use the Java Jar command.

CJ
0
 
LVL 1

Author Comment

by:ltdang7
ID: 7115017
ok, I have created a jar by going into a CMD and typing

jar cf mark.jar insertBean.class

This created a file called mark.jar with the insertBean and the manifest file.
It is located in the /WEB-INF/classes folder off my ROOT directory.
In my JSP page I have this entry

<jsp:useBean id="insert" class="mark.insertBean" scope="session"/>

and when I load the page it gives my this error


An error occurred at line: 6 in the jsp file: /beans.jsp

Generated servlet error:
C:\Program Files\Apache Tomcat 4.0\work\localhost\_\beans$jsp.java:61: Class mark.insertBean not found.
                mark.insertBean insert = null;
                    ^


An error occurred at line: 6 in the jsp file: /beans.jsp

Generated servlet error:
C:\Program Files\Apache Tomcat 4.0\work\localhost\_\beans$jsp.java:64: Class mark.insertBean not found.
                    insert= (mark.insertBean)
                                 ^


An error occurred at line: 6 in the jsp file: /beans.jsp

Generated servlet error:
C:\Program Files\Apache Tomcat 4.0\work\localhost\_\beans$jsp.java:69: Class mark.insertBean not found.
                            insert = (mark.insertBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "mark.insertBean");


I get the feeling that I'm doing somthing really stupid! Please the idiot!
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7115027
jars need to be put in the lib directory.

WEB-INF\lib

CJ
0
 
LVL 1

Author Comment

by:ltdang7
ID: 7115056
Sorry, gives the same error!

I'm increasing the points to 100 to cover the hard work done already.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 19

Expert Comment

by:cheekycj
ID: 7115064
can you try it by putting the insertBean.class
in
/WEB-INF/classes/mark

and see what happens then.

CJ
0
 
LVL 1

Author Comment

by:ltdang7
ID: 7115074
same error...

An error occurred at line: 6 in the jsp file: /beans.jsp

Generated servlet error:
C:\Program Files\Apache Tomcat 4.0\work\localhost\_\beans$jsp.java:61: Class mark.insertBean not found.
                mark.insertBean insert = null;
                    ^


An error occurred at line: 6 in the jsp file: /beans.jsp

Generated servlet error:
C:\Program Files\Apache Tomcat 4.0\work\localhost\_\beans$jsp.java:64: Class mark.insertBean not found.
                    insert= (mark.insertBean)
                                 ^


An error occurred at line: 6 in the jsp file: /beans.jsp

Generated servlet error:
C:\Program Files\Apache Tomcat 4.0\work\localhost\_\beans$jsp.java:69: Class mark.insertBean not found.
                            insert = (mark.insertBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "mark.insertBean");
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7115083
ok.. can you post your mark.insertBean code?

and then your JSP.

I wanna try it out.

CJ
0
 
LVL 1

Author Comment

by:ltdang7
ID: 7115105
thanks for your support...

ftp://henry.27south.com
anonymous access

the files (insertBean.class,beans.jsp and mark.jar) are in the root directory
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7115111
can you put the source of insertBean in there too.

CJ
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7115117
btw: nice collection of files :-)
0
 
LVL 1

Author Comment

by:ltdang7
ID: 7115134
thanks, I saw you routing around!
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7115138
:-)

can you post the code for the bean or even just email it to me:

cheekycj@yahoo.com

CJ
0
 
LVL 1

Author Comment

by:ltdang7
ID: 7115142
it's on there, try again
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7115158
got it.

CJ
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7115163
in insertBean.java

add the following line at the top:

package mark;

Now it should work.

CJ
0
 
LVL 1

Author Comment

by:ltdang7
ID: 7116303
The package entry has been added, but unfornatelly no change in the error message. It looks like the complier just does not know where the file is and I don't know what folder it is looking in!
0
 
LVL 19

Accepted Solution

by:
cheekycj earned 110 total points
ID: 7116430
I added:

package mark;

to the top of insertBean.java

put it in my WEB-INF/classes/mark/
directory

loaded beans.jsp and it worked fine.

I didn't try the jar but I did notice that your jar didn't have the directory hierarchy.

so when you want to create the jar you must do the following:

create a mark directory.
compile insertBean in this directory.

To create the jar.. go up one level.

now run:

jar -cf mark.jar mark/*

that should create the jar with the proper directory structure.

You will have to put this in your lib directory.

Also restart Tomcat if need be.

HTH,
CJ
0
 
LVL 1

Author Comment

by:ltdang7
ID: 7116442
Hurra! It worked. thank you thank you thank you
0
 
LVL 1

Author Comment

by:ltdang7
ID: 7116449
This guy is a genius, triple 'A' rating!
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7116616
Glad I could help and Thanx for the "A".

CJ
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
We have come a long way with backup and data protection — from backing up to floppies, external drives, CDs, Blu-ray, flash drives, SSD drives, and now to the cloud.
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now