tigerSG
asked on
Using of JavaBean
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:useB ean>
<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.JasperEx ception: 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 \Standalon e\localhos t\_\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 \Standalon e\localhos t\_\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.
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:useB
<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.JasperEx
An error occurred at line: 8 in the jsp file: /myjsp/footer.jsp
Generated servlet error:
C:\jakarta-tomcat-4.0\work
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
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.
compile your footer1 class and put it to the tomcat's 'classes' directory
ASKER
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-IN F\classes
Am I right?
Tomcat\webapps\ROOT\WEB-IN
Am I right?
Yup, that should work if your jsp is in the folder Tomcat\webapps\ROOT
Yup, that should work if your jsp is in the folder Tomcat\webapps\ROOT
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
Does the directory
Tomcat\classes
exist on your machine?
Tomcat\classes
exist on your machine?
ASKER
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?
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\classe s 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!
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!