?
Solved

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

Posted on 2002-06-26
31
Medium Priority
?
279 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
[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
  • 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
Independent Software Vendors: 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!

 
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 28

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
 
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 440 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

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!

Question has a verified solution.

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

The well known Cerber ransomware continues to spread this summer through spear phishing email campaigns targeting enterprises. Learn how it easily bypasses traditional defenses - and what you can do to protect your data.
Introducing Priority Question, our latest feature.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

800 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