Unable RUN Java Bean in JSP under Tomcat 5.0

K

k.chinnareddy

Hi
This is my bean source.

public class Counter1 implements java.io.Serializable
{
int count=0;
public Counter1(){}
public int getCount()
{
count++;
return this.count;
}

public void setCount(int count)
{
this.count=count;
}
}

I have stored class file under example web application

C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\example
\WEB-INF\classes\MyBean

jsp file placed under example

C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\example

<%@ page import="MyBean.*" %>
<html>
<head>
<title>Bean class</title>
</head>
<body>
<jsp:useBean id="hello" class="MyBean.Counter1"/>
<jsp:setProperty name="hello" property="count" value="3" />
<jsp:getProperty name="hello" property="count" />

</body>
</html>

When I am calling my jsp file
http://localhost:8080/example/counter.jsp

error is like this:

javax.servlet.ServletException: MyBean/Counter1 (wrong name: Counter1)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:244)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

java.lang.NoClassDefFoundError: MyBean/Counter1 (wrong name: Counter1)
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(ClassLoader.java:620)
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:
124)

org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:
1634)

org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:
860)

org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:
1307)

org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:
1189)
org.apache.jasper.compiler.Generator
$GenerateVisitor.visit(Generator.java:1214)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Generator.generate(Generator.java:3272)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:244)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)

org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:
511)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:
295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:
292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note The full stack trace of the root cause is available in the Apache
Tomcat/5.0.28 logs.


Please tell me what would be the problem. Your help will be
appreciated
May be I am missing Important step
 
L

Lew

Hi
This is my bean source.

public class Counter1 implements java.io.Serializable
{
int count=0;
public Counter1(){}
public int getCount()
{
count++;
return this.count;
}

public void setCount(int count)
{
this.count=count;
}
}

I have stored class file under example web application

C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\example
\WEB-INF\classes\MyBean

Put Counter1 in the MyBean package. Better yet, change that to the 'mybean'
package and put Counter1 there. Your class file will wind up in the
corresponding classpath directory, WEB-INF/classes/mybean/Counter1.class.

How are you doing the compilation and build, via command-line tools? Ant?
 
K

k.chinnareddy

Put Counter1 in the MyBean package. Better yet, change that to the 'mybean'
package and put Counter1 there. Your class file will wind up in the
corresponding classpath directory, WEB-INF/classes/mybean/Counter1.class.

How are you doing the compilation and build, via command-line tools? Ant?

I have stored Counter1 in MyBean package. Then it was working very
fine.

Thank you very much
chinna
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top