Unable RUN Java Bean in JSP under Tomcat 5.0

Discussion in 'Java' started by k.chinnareddy@gmail.com, Jan 9, 2008.

  1. Guest

    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
    , Jan 9, 2008
    #1
    1. Advertising

  2. Lew Guest

    wrote:
    > 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?

    --
    Lew
    Lew, Jan 9, 2008
    #2
    1. Advertising

  3. Guest

    On Jan 9, 8:33 pm, Lew <> wrote:
    > wrote:
    > > 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?
    >
    > --
    > Lew


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

    Thank you very much
    chinna
    , Jan 10, 2008
    #3
  4. Lew Guest

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


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


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

    --
    Lew
    Lew, Jan 10, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Max

    jsp/bean/tomcat

    Max, Jul 6, 2003, in forum: Java
    Replies:
    0
    Views:
    2,192
  2. Markku Salminen
    Replies:
    3
    Views:
    5,833
    Michael Borgwardt
    Jan 21, 2004
  3. Takeshi
    Replies:
    0
    Views:
    479
    Takeshi
    Jan 28, 2004
  4. kumar
    Replies:
    1
    Views:
    527
    Wendy S
    Feb 13, 2004
  5. david wolf

    run jsp under tomcat in Linux

    david wolf, Apr 12, 2006, in forum: Java
    Replies:
    1
    Views:
    777
Loading...

Share This Page