Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Servlet can't recognise the package for Java beans

 
Janet Yap
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
the servlet can recognise the package after i have reset the classpath.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic