wood burning stoves 2.0*
The moose likes Tomcat and the fly likes Java Servlet can't recognise the package for Java beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Java Servlet can Watch "Java Servlet can New topic
Author

Java Servlet can't recognise the package for Java beans

Janet Yap
Greenhorn

Joined: Mar 13, 2004
Posts: 24
I have create a java bean named TransactionBean and save it under C:\Tomcat\webapps\examples\WEB-INF\classes\bean
The transaction codes are started as follows:
__________________________________________________
package beans;
public class TransactionBean
{
all the codes is writen here
}
_______________________________________________________________________
This java bean is used by a java servlet(TransactionHandler.java)that has the follwoing codes:
_______________________________________________________________________
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.*;
import beans.TransactionBean;

public class TransactionHandler extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException
{
int studentId=Integer.parseInt(req.getParameter("studentId"));
............some other codes..........

TransactionBean trans= new TransactionBean();
trans.setStudentId(rst.getInt("student_id"));

}
___________________________________________________________________________
I have no problem in compiling the java beans.
However, when i compile the java servlet(TransactionHandler.java), I get these error message:
C:\Tomcat\webapps\examples\WEB-INF\classes>javac TransactionHandler.java
TransactionHandler.java:6: package beans does not exist
import beans.TransactionBean;
^
TransactionHandler.java:31: cannot resolve symbol
symbol : class TransactionBean
location: class TransactionHandler
TransactionBean trans= new TransactionBean();
^
May I know how this problem can be solved?
Thank You.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12760
    
    5
Your compiler can't see the class file for beans.TransactionBean
This might be due to your classpath or to incorrectly named directory in:
Is it bean or beans?
Janet Yap
Greenhorn

Joined: Mar 13, 2004
Posts: 24
Thanks.
the servlet can recognise the package after i have reset the classpath.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12760
    
    5
Great! I really recommend using ANT for servlet projects so you don't get all tangled up in Classpath issues. It is a bit of a learning curve but you will be glad you did.
Bill
 
 
subject: Java Servlet can't recognise the package for Java beans
 
Similar Threads
unable to compile servlet
struts
using servlet to set bean property and display it in JSP
problem with struts
Compiling servlet file