| 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: 12268
|
|
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: 12268
|
|
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
|
|
|