aspose file tools*
The moose likes Servlets and the fly likes Regarding to exercise in Head first Servlets & JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Regarding to exercise in Head first Servlets & JSP" Watch "Regarding to exercise in Head first Servlets & JSP" New topic
Author

Regarding to exercise in Head first Servlets & JSP

Albert Liou
Greenhorn

Joined: May 28, 2006
Posts: 7
Hello,

Could anyone help ?

I used the Head First Servlets & JSP for studying the Servlet/JSP. And I was got stuck on the exercise in Chapter 3.

The webpage displaying is OK. But when I try to run the first edition of Controller Servlet. I got the following error:

HTTP Status 404 - /Beer-v1/SelectBeer.do

type Status report

message /Beer-v1/SelectBeer.do

description The requested resource (/Beer-v1/SelectBeer.do) is not available.

Apache Tomcat/5.5.17

My program environment is Java 5.0.06/Tomcat 5.5.17 (Window 2000 professional).

I have double checked my code spelling and the directory is follow strictly as the book suggest.

Can anyone help to give some advise ?

Thanks in advance!!

Albert
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Please post your servlet-mapping from web.xml.
There's probably no mapping associated with SelectBeer.do


[My Blog]
All roads lead to JavaRanch
Albert Liou
Greenhorn

Joined: May 28, 2006
Posts: 7
Thanks for your response!

Here is my web.xml

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<servlet>
<servlet-name>Ch3 Beer</servlet-name>
<servlet-class>com.example.web.BeerSelect</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Ch3 Beer</servlet-name>
<url-pattern>/SelectBeer.do</url-pattern>
</servlet-mapping>

</web-app>

Looking forward to hear from you soon!
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by Albert Liou:
Hello,

Could anyone help ?

I used the Head First Servlets & JSP for studying the Servlet/JSP. And I was got stuck on the exercise in Chapter 3.

The webpage displaying is OK. But when I try to run the first edition of Controller Servlet. I got the following error:

HTTP Status 404 - /Beer-v1/SelectBeer.do

type Status report

message /Beer-v1/SelectBeer.do

description The requested resource (/Beer-v1/SelectBeer.do) is not available.

Apache Tomcat/5.5.17

My program environment is Java 5.0.06/Tomcat 5.5.17 (Window 2000 professional).

I have double checked my code spelling and the directory is follow strictly as the book suggest.

Can anyone help to give some advise ?

Thanks in advance!!

Albert


Might be a wrong guess.

Did you compile the servlet???
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Could you also post your FORM tag please ?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Another thing. What is the name of your web application ?
Is is "Beer-v1" ? (the folder under webapps in Tomcat)
Albert Liou
Greenhorn

Joined: May 28, 2006
Posts: 7
Hello Rathi,

yes, I did compile the servlet file and put it in the directory according to the book suggest.(\Tomcat_5.5\webapps\Beer-v1\WEB-INF\classes\com\example\web\)

Any more advise ?

Thanks!
Albert Liou
Greenhorn

Joined: May 28, 2006
Posts: 7
Hello Satou,

Following is my form tag file :

<html><body>
<h1 align="center">啤酒選擇畫面</h1>
<form method="POST"
action="SelectBeer.do">
選出想喝的啤酒<p>
顏色:
<select name="color" size="1">
<option>Light
<option>amber
<option>brown
<option>dark
</select>
<br><br>
<center>
<input type="SUBMIT">
</center>
</form></body></html>

And I put this file in \Tomcat_5.5\webapps\Beer-v1\

Thanks
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Where did you put web.xml ?
Albert Liou
Greenhorn

Joined: May 28, 2006
Posts: 7
Hello Satou,

I put the web.xml in \Tomcat_5.5\webapps\Beer-v1\WEB-INF\


Appreciate for your response.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Mmmm... I don't know. The error message seems to point out that the mapping between your form action and your servlet is not found.
The mapping is either wrong (but it seems correct here), or web.xml is not found.

Are you sure you have \Tomcat_5.5\webapps\Beer-v1\WEB-INF\web.xml, with the exact content you've posted above ?
And Did you try to restart Tomcat ?
Albert Liou
Greenhorn

Joined: May 28, 2006
Posts: 7
I am still can not resolve the problem, But I am still try to work it out. Can anyone help to explain the meaning of "...:classes:." in the following command, I do not know what this for ?

"cd MyProjects/beerV1

javac -classpath /Users/bert/Applications2/tomcat/commom/lib/servlet-api.jar:classes:. -d classes src/com/example/web/BeerSelect.java"

Thanks a lot!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

"classes" is the name of the directory where your class files are.
So it says : put the "classes" directory into the CLASSPATH, so that the compiler can find my class files.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

You probably want to type /Users/bert/Applications2/tomcat/common/lib/servlet-api.jar, not /Users/bert/Applications2/tomcat/commom/lib/servlet-api.jar
Vinay Thippeswamy
Greenhorn

Joined: Apr 26, 2006
Posts: 15
try creating a new directory under webapps say "beer" and transfer all your files there. restart tomcat and enter the new url it might work. i had the same problem.

regards
vinay
suneel kota
Greenhorn

Joined: Jun 06, 2006
Posts: 1
Hi Albert,

I think you might have done mistacke when you are compiling your servlet java file in package.. you need use the cpmmand like
javac -d servlet.java

Then only all your packages will be created and you can run your program successfully..

Thanking You
SuneelKota
Weichia Huang
Greenhorn

Joined: Aug 03, 2006
Posts: 1
Try to remove one or more documentory under C:\Tomcat\webapps\ such as "webdav". I had the same experience as yours and found that way would be useful. (A BUG in Tomcat?)
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Weichia Huang,

Welcome to Javaranch.

The thread you've posted to is months old.
It should be safe to assume that the original poster has moved on from this issue by now.

Also, Tomcat is one of (if not the) most popular servlet containers in the world. The Head First series is also extremely popular. If there was a bug in Tomcat that kept the examples in that book from running, there would be many Many posts in here from people complaining about it. Since there are not, it is usually best to assume first, that the problem is with your code.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding to exercise in Head first Servlets & JSP
 
Similar Threads
Tomcat 5.5 - application development
Headfirst ch3 Beerselect submit button not working
Tomcat 5.5 manual deployment
Problems with the Example from HF Servlets & JSP in Chapter 3
Head First Servlet JSP: BeerSelect example: requested resource not available