Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Servlet cannot detect bean

Posted on 2005-03-28
11
Medium Priority
?
241 Views
Last Modified: 2010-04-01

Hi!

I was trying to compile RandomNumberServlet.java, but got this error.
symbol  : class NumberBean
location: class coreservlets.RandomNumberServlet
    NumberBean bean = new NumberBean(Math.random());
    ^
C:\jakarta-tomcat-5.5.7\webapps\~dkim18\WEB-INF\classes\coreservlets\RandomNumberServlet.java:15: cannot find symbol
symbol  : class NumberBean
location: class coreservlets.RandomNumberServlet
    NumberBean bean = new NumberBean(Math.random());
                          ^
2 errors

Why am I having this error even though NumberBean compiled
+++++++++++++++

package coreservlets;  

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class RandomNumberServlet extends HttpServlet {
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
      throws ServletException, IOException {
    NumberBean bean = new NumberBean(Math.random());
    request.setAttribute("randomNum", bean);
    String address = "/WEB-INF/mvc-sharing/RandomNum.jsp";
    RequestDispatcher dispatcher =
      request.getRequestDispatcher(address);
    dispatcher.forward(request, response);
  }
}
++++++++++++
package coreservlets;

public class NumberBean {
  private double num = 0;

  public NumberBean(double number) {
    setNumber(number);
  }
 
  public double getNumber() {
    return(num);
  }
 
  public void setNumber(double number) {
    num = number;
  }
}
++++++++
thanks,
0
Comment
Question by:dkim18
  • 5
  • 5
11 Comments
 

Author Comment

by:dkim18
ID: 13644297
this is my classpath
classpath
C:\jakarta-tomcat-5.5.7/common/lib/servlet-api.jar;C:\jakarta-tomcat-5.5.7/install_dir/common/lib/jsp-api.jar
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 13644417
in your servlet do a import coreservlets.*
it should do the trick
0
 

Author Comment

by:dkim18
ID: 13644450
I added
import coreservlets.*;
but still same error...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 13644478
is your class is in the same folder where you are compiling your servlet? it should be available there.. and if its there.. your servlet should compile....
0
 

Author Comment

by:dkim18
ID: 13644507
yes, everything is under coreservlets folder...
NumberBean.class is there too.
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 13644522
add coreservlet in your class path..
do set classpath=%classpath%;C:\jakarta-tomcat-5.5.7\webapps\~dkim18\WEB-INF\classes\coreservlets\NumberBean.class;.;

the last period is to add the current working directory to the class path
0
 

Author Comment

by:dkim18
ID: 13644603
Still didn't work..
I am using windows 2000 and this is my classpath
C:\jakarta-tomcat-5.5.7/common/lib/servlet-api.jar;C:\jakarta-tomcat-5.5.7/install_dir/common/lib/jsp-api.jar;C:\jakarta-tomcat-5.5.7\webapps\~dkim18\WEB-INF\classes\coreservlets\NumberBean.class;.;
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 13644647
thats strange...
How you are compiling the servlet? is it command line or you are using some kind of SDK for it??

and try changing your class path to

C:\jakarta-tomcat-5.5.7\webapps\~dkim18\WEB-INF\classes\coreservlets.NumberBean.class;.; ideally speaking the last one should have worked also
0
 

Author Comment

by:dkim18
ID: 13644700
I am using TextPad, but it compiled NumberBean.java file.
0
 
LVL 19

Accepted Solution

by:
Kuldeepchaturvedi earned 400 total points
ID: 13647026
try putting everything from here to MyTest that we just created and see if we can compile it there..
change the classpath to point to MyTest and also change the servlet from

NumberBean bean = new NumberBean(Math.random());

to
coreservlets.NumberBean bean = new coreservlets.NumberBean(Math.random());

see if it compiles
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13649503
When you compile change:
C:\jakarta-tomcat-5.5.7/common/lib/servlet-api.jar;C:\jakarta-tomcat-5.5.7/install_dir/common/lib/jsp-api.jar;C:\jakarta-tomcat-5.5.7\webapps\~dkim18\WEB-INF\classes\coreservlets\NumberBean.class;.;
to
C:\jakarta-tomcat-5.5.7/common/lib/servlet-api.jar;C:\jakarta-tomcat-5.5.7/install_dir/common/lib/jsp-api.jar;C:\jakarta-tomcat-5.5.7\webapps\~dkim18\WEB-INF\classes\;.;
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use this step by step method when setting up QuickBooks Online. They will allow you to explore the various features of the advanced settings available to you.
This blog will spread awareness about Dropbox. We have given the statements based upon our experience. Along with this, there is a section of some new plans that should be added in Dropbox this year. This will make the storage service enhanced from …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question