• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Java Servlet can't recognise the package for Java beans

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Self destruct mode activated. Instructions for deactivation encoded in this tiny ad.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic