Solved

!! JSP Shopping Cart !!

Posted on 2002-05-26
23
665 Views
Last Modified: 2013-11-29
Hi Expert,

I am currently running Tomcat on my local machine with the intention to create a simple shopping cart system in JSP.

I have downloaded a shopping cart source sample from http://www.javaworld.com/jw-12-1999/ssj/ShoppingCart.jar

The problem is that I cannot compile SHOPPINGSERVLET.JAVA into a class file using JAVAC.exe. A bunch of error messages will display in the DOS box.

The other java file CD.JAVA can be compiled with no problems.

Am I missing certain packages or is it entirely something else that causes it not to compile?

0
Comment
Question by:Frohike
  • 12
  • 6
  • 5
23 Comments
 
LVL 19

Expert Comment

by:cheekycj
ID: 7036201
do you have the jsdk both standard and j2ee on your machine?

also if you are just looking for a shipping cart also check out:
http://www.devx.com/upload/free/features/javapro/2000/06jun00/gb0006/gb0006.asp

we really can't help you with what is wrong unless you post the error messages that the compiler is giving you.

CJ

0
 
LVL 92

Expert Comment

by:objects
ID: 7036483
Sounds like you don't have j2ee installed as CJ suggests.
You need to install it, or alternatively you should be able to find the required jar in your tomcat lib directory. Simply include it in your classpath.
0
 

Author Comment

by:Frohike
ID: 7036749
Here's the javac.exe error messages when compiling the ShoppingServlet.java file. There are a whole bunch of them. I hope this will help explain it a little better.

----------------------------------------------------------
C:\j2sdk1.4.0\bin>javac shoppingservlet.java
error: cannot read: shoppingservlet.java
1 error

C:\j2sdk1.4.0\bin>javac shoppingservlet.java
shoppingservlet.java:3: package javax.servlet does not exist
import javax.servlet.*;
^
shoppingservlet.java:4: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
shoppingservlet.java:5: package shopping does not exist
import shopping.CD;
                ^
shoppingservlet.java:6: cannot resolve symbol
symbol  : class HttpServlet
location: class ShoppingServlet
public class ShoppingServlet extends HttpServlet {
                                     ^
shoppingservlet.java:7: cannot resolve symbol
symbol  : class ServletConfig
location: class ShoppingServlet
  public void init(ServletConfig conf) throws ServletException  {
                   ^
shoppingservlet.java:7: cannot resolve symbol
symbol  : class ServletException
location: class ShoppingServlet
  public void init(ServletConfig conf) throws ServletException  {
                                              ^
shoppingservlet.java:10: cannot resolve symbol
symbol  : class HttpServletRequest
location: class ShoppingServlet
  public void doPost (HttpServletRequest req, HttpServletResponse res)
                      ^
shoppingservlet.java:10: cannot resolve symbol
symbol  : class HttpServletResponse
location: class ShoppingServlet
  public void doPost (HttpServletRequest req, HttpServletResponse res)
                                              ^
shoppingservlet.java:11: cannot resolve symbol
symbol  : class ServletException
location: class ShoppingServlet
      throws ServletException, IOException {
             ^
shoppingservlet.java:69: cannot resolve symbol
symbol  : class HttpServletRequest
location: class ShoppingServlet
  private CD getCD(HttpServletRequest req) {
                   ^
shoppingservlet.java:69: cannot resolve symbol
symbol  : class CD
location: class ShoppingServlet
  private CD getCD(HttpServletRequest req) {
          ^
shoppingservlet.java:8: cannot resolve symbol
symbol  : variable super
location: class ShoppingServlet
    super.init(conf);
    ^
shoppingservlet.java:12: cannot resolve symbol
symbol  : class HttpSession
location: class ShoppingServlet
    HttpSession session = req.getSession(false);
    ^
shoppingservlet.java:27: cannot resolve symbol
symbol  : class CD
location: class ShoppingServlet
        CD aCD = getCD(req);
        ^
shoppingservlet.java:34: cannot resolve symbol
symbol  : class CD
location: class ShoppingServlet
            CD cd = (CD) buylist.elementAt(i);
            ^
shoppingservlet.java:34: cannot resolve symbol
symbol  : class CD
location: class ShoppingServlet
            CD cd = (CD) buylist.elementAt(i);
                     ^
shoppingservlet.java:47: cannot resolve symbol
symbol  : class ServletContext
location: class ShoppingServlet
      ServletContext sc = getServletContext();
      ^
shoppingservlet.java:47: cannot resolve symbol
symbol  : method getServletContext  ()
location: class ShoppingServlet
      ServletContext sc = getServletContext();
                          ^
shoppingservlet.java:48: cannot resolve symbol
symbol  : class RequestDispatcher
location: class ShoppingServlet
      RequestDispatcher rd = sc.getRequestDispatcher(url);
      ^
shoppingservlet.java:53: cannot resolve symbol
symbol  : class CD
location: class ShoppingServlet
        CD anOrder = (CD) buylist.elementAt(i);
        ^
shoppingservlet.java:53: cannot resolve symbol
symbol  : class CD
location: class ShoppingServlet
        CD anOrder = (CD) buylist.elementAt(i);
                      ^
shoppingservlet.java:64: cannot resolve symbol
symbol  : class ServletContext
location: class ShoppingServlet
      ServletContext sc = getServletContext();
      ^
shoppingservlet.java:64: cannot resolve symbol
symbol  : method getServletContext  ()
location: class ShoppingServlet
      ServletContext sc = getServletContext();
                          ^
shoppingservlet.java:65: cannot resolve symbol
symbol  : class RequestDispatcher
location: class ShoppingServlet
      RequestDispatcher rd = sc.getRequestDispatcher(url);
      ^
shoppingservlet.java:79: cannot resolve symbol
symbol  : class CD
location: class ShoppingServlet
    CD cd = new CD();
    ^
shoppingservlet.java:79: cannot resolve symbol
symbol  : class CD
location: class ShoppingServlet
    CD cd = new CD();
                ^
26 errors

C:\j2sdk1.4.0\bin>
----------------------------------------------------------

0
 
LVL 92

Expert Comment

by:objects
ID: 7036752
Yes those errors are beause you do not have j2ee installed as mentioned above. Either install j2ee, or add servlet.jar from your tomcat lib directory to your classpath.
0
 

Author Comment

by:Frohike
ID: 7036769
Sorry. Forget about the first set:

C:\j2sdk1.4.0\bin>javac shoppingservlet.java
error: cannot read: shoppingservlet.java
1 error
0
 
LVL 92

Expert Comment

by:objects
ID: 7036771
Does the file shoppingservlet.java exist in C:\j2sdk1.4.0\bin?
0
 
LVL 92

Expert Comment

by:objects
ID: 7036772
Try:

javac ShoppingServlet.java file
0
 

Author Comment

by:Frohike
ID: 7036823
Sorry. Forget about the first set:

C:\j2sdk1.4.0\bin>javac shoppingservlet.java
error: cannot read: shoppingservlet.java
1 error
0
 

Author Comment

by:Frohike
ID: 7036840
Yes, but I delete the java file as soon as I have compiled it into a class file. The first error there is a mistake as I tried running javac without the java file in the bin folder.
0
 

Author Comment

by:Frohike
ID: 7036842
If I install j2ee, would I also need to first uninstall j2sdk? Or can they both co-exist?

0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7037542
yes. you need to install jsdk and j2ee.

also in Java filenames are case sensitive.

so javac shoppingcart.java is not the same as javac ShoppingCart.java

Why do you delete the file after you compile it?

that  is probably why it is saying it can't find it.  if you are trying to run it.. that is a different story.

CJ
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 92

Expert Comment

by:objects
ID: 7037832
> If I install j2ee, would I also need to first uninstall j2sdk?

No, but if you just need it to compile this example it's probably easier to use the jar from TomCat to avoid having to install j2ee.


0
 

Author Comment

by:Frohike
ID: 7039237
I'm also a little confused as to what the classpath is that you refer to? I have read many examples, however, they all refer to an older version of Tomcat (not 4.0).

The sample web apps will tell me to place certain files into folders that do not seem to exist in the latest version of Tomcat. Take for example, the Shopping Cart web app from the above URL.

Note: is JavaServer Web Development Kit (JSWDK) the same as the current J2EE or J2SDK?

The other thing is that I cannot always get to run a jsp file properly in IE6.0. Assuming that I have a folder called "cars" under ".../webapps/". If I then enter this URL "http://localhost:8080/Test/com/cars" it will load the directory listings which shows all the JSP files contained within, including the "WEB-INF/classes/com/cars" folders.

But when I rename "Test" to another name, and re-enter the URL, Tomcat will throw a 404 error on me. It appears that the resource is not available, which clearly is sitting there, but with a different folder name.

Is J2SDK & Tomcat not setup correctly? Does it require me to manually set paths etc?

0
 

Author Comment

by:Frohike
ID: 7039243
> Assuming that I have
a folder called "cars" under ".../webapps/". <

This was meant to read: [...folder called "Test/com/cars" under...]
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7042880
JSWDK == J2EE

when you rename do you update the context?

CJ
0
 

Author Comment

by:Frohike
ID: 7044011
Well, I guess not, because I don't know what context is. Could you perhaps explain what it means?

What paths would I need to set in autoexec.bat assuming that that's where it's suppose to go.
0
 

Author Comment

by:Frohike
ID: 7044054
Well, I guess not, because I don't know what context is. Could you perhaps explain what it means?

What paths would I need to set in autoexec.bat assuming that that's where it's suppose to go.
0
 

Author Comment

by:Frohike
ID: 7044212
Well, I guess not, because I don't know what context is. Could you perhaps explain what it means?

What paths would I need to set in autoexec.bat assuming that that's where it's suppose to go.
0
 
LVL 19

Accepted Solution

by:
cheekycj earned 50 total points
ID: 7044633
you add contexts in the server.xml file.

for more info check out:
http://www.onjava.com/lpt/a/onjava/2001/04/19/tomcat.html
http://www.devshed.com/Server_Side/Java/JSPDev/page6.html

as far as tomcat env vars.. besides standard jdk add:
CATALINA_HOME which is the paht to which you have installed Tomcat 4.0.

HTH,
CJ
0
 

Author Comment

by:Frohike
ID: 7048370
*sigh* I've just about had enough of Tomcat and JSP! :((

I have finally managed to compile all my classes, only to find out now that my JSP pages will not load in IE6.

Thinking that it may be something wrong with Tomcat, I reintalled, but to no avail.

Why is this hapenning? Something works now and then another that use to work now doesn't work!

They display a white screen with nothing on it. What's causing this?

I know that Tomcat is running, because when I type the appropriate URL, it displays a directory listing of all the web applications that I have played around with, including my shopping web site. When I load the first page, which is a HTML, click on a button, it should action a JSP file.

This all worked fine prior to compiling two other classes (I'm not implying that this is the root cause). I could even simply click on any JSP and it would display at least something. Even if it was an error message. Now, it is just a blank white page??

HELP!
0
 

Author Comment

by:Frohike
ID: 7048382
*sigh* I've just about had enough of Tomcat and JSP! :((

I have finally managed to compile all my classes, only to find out now that my JSP pages will not load in IE6.

Thinking that it may be something wrong with Tomcat, I reintalled, but to no avail.

Why is this hapenning? Something works now and then another that use to work now doesn't work!

They display a white screen with nothing on it. What's causing this?

I know that Tomcat is running, because when I type the appropriate URL, it displays a directory listing of all the web applications that I have played around with, including my shopping web site. When I load the first page, which is a HTML, click on a button, it should action a JSP file.

This all worked fine prior to compiling two other classes (I'm not implying that this is the root cause). I could even simply click on any JSP and it would display at least something. Even if it was an error message. Now, it is just a blank white page??

HELP!
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7050168
thats interesting.. even the samples are not working??

try clearing out the work directory and your cache.  See what happens.  Maybe put some debug code at the top of the code to see if it is even being loaded.

CJ
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7075690
any updates for us?

CJ
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

E-commerce is quite a gambling world, and you should never entrust your business to a lucky chance. In order to outrun your competitors in a race to attract as many customers as possible, you need to have a well thought-out strategy under your belt.…
SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now