bad class and import problem!

import java.util.ArrayList;

import java.util.ListIterator;

import java.util.Iterator;

import mybeans.shoppingcart.OrderItem;

import javax.servlet.*;

import javax.servlet.http.*;

public class CartBean {

private ArrayList items = new ArrayList();

public void addItem(OrderItem itm) {

items.add(itm);

}

public void removeItem(OrderItem itm) {

items.remove(itm);

}

public ArrayList getProducts() {

return items;

}

public OrderItem getItem(int i) {

return (OrderItem)items.get(i);

}

public int getItemSize() {

return items.size();

}

public Iterator getContents() {

System.out.println(items.size());

return items.iterator();

}

}

when I compile this java file I get these errors, can anyone explain

G:\Year 4\It Project\Jsp\resin-3.0.14\webapps\ROOT\WEB-INF\shoppingcart\CartBean.java:4: package shoppingcart does not exist

import shoppingcart.OrderItem;

^

G:\Year 4\It Project\Jsp\resin-3.0.14\webapps\ROOT\WEB-INF\shoppingcart\CartBean.java:5: package javax.servlet does not exist

import javax.servlet.*;

^

G:\Year 4\It Project\Jsp\resin-3.0.14\webapps\ROOT\WEB-INF\shoppingcart\CartBean.java:6: package javax.servlet.http does not exist

import javax.servlet.http.*;

^

G:\Year 4\It Project\Jsp\resin-3.0.14\webapps\ROOT\WEB-INF\shoppingcart\CartBean.java:13: cannot access OrderItem

bad class file: .\OrderItem.class

class file contains wrong class: shoppingcart.OrderItem

Please remove or make sure it appears in the correct subdirectory of the classpath.

public void addItem(OrderItem itm) {

[1748 byte] By [mar-k-a] at [2007-11-26 19:19:15]
# 1

Check your classpath, its probably missing a few references. Also check which folder is condered to the base of the project, for example:

won't work:

current dir: /mydir/shoppingcart/

javac CartBean.java

will work:

current dir: /mydir/

javac shoppingcart/CartBean.java

ajmasxa at 2007-7-9 21:35:25 > top of Java-index,Desktop,Developing for the Desktop...
# 2
Should they be in the same folder called shopping cart or should they be in different folders I have both in same folder web-inf/classes/cartbean.javaweb-inf/classes/OrderItem.java, OrderItem.class
mar-k-a at 2007-7-9 21:35:25 > top of Java-index,Desktop,Developing for the Desktop...
# 3
Try the following forum (about JSP technology) http://forum.java.sun.com/forum.jspa?forumID=45
UncleSAMa at 2007-7-9 21:35:25 > top of Java-index,Desktop,Developing for the Desktop...
# 4
Create a directory called "shoppingcart" under /web-inf/classes/shoppingcart and put the "OrderItem.class" in that.
cvasu4a at 2007-7-9 21:35:25 > top of Java-index,Desktop,Developing for the Desktop...
# 5

Hi

im suggesting u to create packages like this always at the starting of ur peoject.

this is the correct way of writing programs..

WEB-INF/classes/

com.in.delivery(projectname).connection

( for JDBC releate progrmas

com.in.devivery.controller(for servlet programs)

now u import the package that u want as import com.in.delivery.connection loke that.

u wont confuse at all.

Yuvaraj.Ma at 2007-7-9 21:35:25 > top of Java-index,Desktop,Developing for the Desktop...