aspose file tools*
The moose likes JSP and the fly likes java bean problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "java bean problem" Watch "java bean problem" New topic
Author

java bean problem

padma patil
Ranch Hand

Joined: Nov 06, 2001
Posts: 41
Hi,
I am getting error in jsp page at call to the Bean method.
I am useing tomcat webserver and copying the complied bean class into
c:>tomacat install dir/webapps/ROOL/WEB-INF/classes
Here is .jsp file contents
<html>
<body>
<!-- declare the variables -->
<%
String sFindText = request.getParameter("txtFind");
String sReplaceWith =request.getParameter("txtReplace");
%>
<!-- use FinfandReplaceBean -->
<jsp:useBean class="MyBean" id="b1" scope="session" />
<%= b1.hello("padma") %>
</body>
</html>
MyBean.java
public class MyBean
{
public String hello(String name)
{
return name;
}
}
and I am getting errors as
An error occurred at line: 11 in the jsp file: /FindAndReplace.jsp
Generated servlet error:
C:\jakarta-tomcat-4.0.1\jakarta-tomcat-4.0.1\work\localhost\_\FindAndReplace$jsp.java:69: Class org.apache.jsp.MyBean not found.
MyBean b1 = null;
^

An error occurred at line: 11 in the jsp file: /FindAndReplace.jsp
Generated servlet error:
C:\jakarta-tomcat-4.0.1\jakarta-tomcat-4.0.1\work\localhost\_\FindAndReplace$jsp.java:72: Class org.apache.jsp.MyBean not found.
b1= (MyBean)
^
An error occurred at line: 11 in the jsp file: /FindAndReplace.jsp
Generated servlet error:
C:\jakarta-tomcat-4.0.1\jakarta-tomcat-4.0.1\work\localhost\_\FindAndReplace$jsp.java:77: Class org.apache.jsp.MyBean not found.
b1 = (MyBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "MyBean");
^
3 errors, 1 warning
Do I need to copy MyBean.class file into some other dir?
thanks,
padmashree
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
Classic error. There is a slight bug with JSP especially Tomcat. It can not locate classes that are not in a package! Change this to
package beans;
public class MyBean
{
...
And your jsp useBean to
<jsp:useBean class="beans.MyBean" id="b1" scope="session" />
And it should work.


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
padma patil
Ranch Hand

Joined: Nov 06, 2001
Posts: 41
Hi,
I have added package bean in MyBean file but still getting same error.
let me tel you my file dir structure
c:\servletDev\bean\MyBean.java
I haVe set servletDev path in CLASSPATH
c\tomcat dir\webapps\ROOt\web-inf\classes\MyBean.class
c\tomcat dir\webapps\ROOt\First.jsp
WHERE I AM DOING WROUNG??
PADMASHREE
Pranit Saha
Ranch Hand

Joined: Sep 09, 2001
Posts: 130
Hi,
I think it'll be better to make the beans folder in this path..
TOMCAT_HOME\webapps\examples\web-inf\classes..
Just test it..
Pranit..
 
jQuery in Action, 2nd edition
 
subject: java bean problem
 
Similar Threads
jsp when compiled cant find bean class see code servlet exception
Newbie: In which directory do I put helper classes/beans
Where does this package go?
shopping cart -MS Access & JSP Connections
import directives for taglib classes?