posted 12 years ago
Hi Susobhan,
I just recently purchased Head First Java Servlets & JSP, and completed this exercise not too long ago. This is my first-ever post on Javaranch. Hopefully what follows will help you (or whomever else reads this) make progress, without denying you the satisfaction of finally figuring it out for yourself.
I'm running Tomcat 6.0 on a Windows 7 workstation. My HeadFirst Java Projects live in c:\JavaProjects, and this exercise lives in c:\JavaProjects\HeadFirstServletsJSP\project1. I also used the environment variable %CATALINA_HOME%, which points to the base path of the Tomcat installation. In my case it's C:\Program Files\Apache Software Foundation\Tomcat 6.0. So, to compile Ch1Servlet.java, after completing steps 1 - 4 in the book, I used the following commands for step 5:
cd c:\JavaProjects\HeadFirstServletsJSP\project1
javac -cp "%CATALINA_HOME%\lib\servlet-api.jar" -d classes src/Ch1Servlet.java
Note the use of quotation marks around the classpath argument, since my Tomcat installation base path contains embedded spaces. After copying the files as described in step 6, since I'm not running Linux I instead used the service console command to start the Tomcat service: sc start tomcat6.
When I first launched a browser and pointed to http://localhost:8080/ch1/Serv1, I got a HTTP 404 error.
After carefully proofreading the deployment descriptor I typed in, it turned out instead that when I created the WEB-INF folder under the webapps/ch1 directory, I wasn't paying enough attention to what I was typing. I held the shift key down when typing the "-", and instead ended up with WEB_INF. After a frustrating period of time, I finally found my typo. Once changed, everything worked fine.
You can also use the service console commands sc stop tomcat6, and sc query tomcat6 to stop Tomcat and find out whether Tomcat is running, respectively.
When you get to the beerV1 project you will need to modify the -cp and -d arguments. The book explains what to do, but read (and type) carefully. I wish you success with your efforts!