?
Solved

Servlet cannot detect bean

Posted on 2005-03-28
11
Medium Priority
?
240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this modest contribution, I want to share with the IT community (especially system administrators, IT Support Engineers and IT Help Desks) about Windows crashes/hangs and how to deal with these particular problems.
I don't pretend to be an expert at this, but I have found a few things that are useful. I hope that sharing them here will help others, so they will not have to face some rather hard choices. Since I felt this to be a topic of enough importance and…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

765 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