Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using of JavaBean

Posted on 2002-04-18
9
Medium Priority
?
348 Views
Last Modified: 2013-11-24
Hi All Experts,

I have difficulties making my JavaBean works. It's just a simply program which uses 1 JSP and 1 Bean program. I've attached the programs and the errors encountered for your reference.

************
Bean
************

import java.io.Serializable;

public class footer1 implements Serializable{

  private String message = "No message.";

  public String getMessage() {
    return message;
  }
   
  public void setMessage(String s) {
    message = s;
  }
}

***********
JSP
***********

<HTML>
<BODY BGCOLOR="WHITE">
  <jsp:useBean id="MyMessage" class="footer1"></jsp:useBean>
  <OL>
   <LI> Initial Message (using getProperty):
     <I> <jsp:getProperty name="MyMessage" property="message" /> </I>
   <LI> <jsp:setProperty name="MyMessage" property="message" value="Meeting" />
     Secret message (after setting):
     <I> <jsp:getProperty name="MyMessage" property="message" /> </I>
  </OL>
 </BODY>
</HTML>

********************
Errors
********************

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 8 in the jsp file: /myjsp/footer.jsp

Generated servlet error:
C:\jakarta-tomcat-4.0\work\Standalone\localhost\_\myjsp\footer$jsp.java:60: Class org.apache.jsp.footer1 not found.
        footer1 MyMessage = null;
        ^
An error occurred at line: 8 in the jsp file: /myjsp/footer.jsp

Generated servlet error:
C:\jakarta-tomcat-4.0\work\Standalone\localhost\_\myjsp\footer$jsp.java:63: Class org.apache.jsp.footer1 not found.
          MyMessage= (footer1)

Is there any errors with my codes? Could anyone help me with this.... By the way, I'm using Tomcat. I've tried in Jrun, my codes are ok and will not generate any errors. So is there something that Tomcat is not letting my codes to be compiled and run successfully? Please advise.

Thank you.
0
Comment
Question by:tigerSG
[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
  • 4
  • 3
  • 2
9 Comments
 
LVL 9

Expert Comment

by:Venci75
ID: 6949858
compile your footer1 class and put it to the tomcat's 'classes' directory
0
 

Author Comment

by:tigerSG
ID: 6949869
By the when I installed Tomcat, there isn't any classes directory. Hence, I created a classes directory under WEB-INF :
Tomcat\webapps\ROOT\WEB-INF\classes

Am I right?
0
 

Expert Comment

by:jodear
ID: 6949903
Yup, that should work if your jsp is in the folder Tomcat\webapps\ROOT
0
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!

 

Expert Comment

by:jodear
ID: 6949905
Yup, that should work if your jsp is in the folder Tomcat\webapps\ROOT
0
 

Accepted Solution

by:
jodear earned 90 total points
ID: 6949955
Also, your bean should be named footer1.java.  If you place footer1.java in the \webapps\ROOT\WEB-INF\classes folder, as Venci75 suggested, compile it there also so that footer1.class will also be created in the same folder.

If you have any trouble compiling footer1.java, just respond here.
0
 

Author Comment

by:tigerSG
ID: 6950421
Well, I have compiled my footer1.java and it's successful. It's just having problem when I'm trying to use it as a bean. I've tried using jrun to run my program, it works. Hence, I'm confused why it's not working in Tomcat.
0
 
LVL 9

Expert Comment

by:Venci75
ID: 6950432
Does the directory
Tomcat\classes
exist on your machine?
0
 

Author Comment

by:tigerSG
ID: 6952268
Nope. There's no such directory in my machine. I've downloaded the software from http://jakarta.apache.org/tomcat and after unzipping it, a directory named jakarta-tomcat-4.0 resides in my machine. By the way, do I need to setup anything in the xml files?
0
 

Expert Comment

by:jodear
ID: 6961969
You don't need to setup anything in the XML files.  A Java bean is usually packaged.  What you have is a java class file, so you can't useBean it.  You can import it though, if you placed it at \WEB-INF\classes folder, or as Venci75 says, at the \jakarta-tomcat-4.0\classes folder.  Then you have to restart Tomcat.

If you really want to use it as a Java bean, you have to redo your footer class as follows:

package myPack;

import java.io.Serializable;

public class footer1 implements Serializable{

 private String message = "No message.";

 public String getMessage() {
   return message;
 }
   
 public void setMessage(String s) {
   message = s;
 }
}

Compile it then place it in the folder \WEB-INF\classes\myPack\.  If there's none, make one.  Make sure that you follow the upper and lower cases since Java is case sensitive.

Hope that works!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

715 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