• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java bean problem

 
padma patil
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
padma patil
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic