• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems with the sample in chapter1 of "Head First Servlets & JSP"

Tim Bohlender
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm reading the book "Head First Servlets & JSP" and get stuck right with the first example, which seems to be pretty common, because during my searches I found many places where they refered to this sample.

Anytime I try to open this sample in the browser I get the error 404 (The requested resource is not available.)

I tryed it with


both didn't work

I also found an entry in this forum


And I also tried different things which I've read in several forums (adding a package, changed the web.xml charset) but I still can't get it to work. I hope someone can help me to figure out whats wrong, and how I can fix it.

Here is my web.xml

initialy the name was "Chapter1 Servlet" but because somebody in a forum entry I found supposed that it could be the problem, but removing this space didn't change anything. Also at first there was no package at all, and I did add this (and the folders), which also didn't change anything.

Here is the actual class

and I deploy and build it using the following ant xml script

As you can see from this script, Tomcat 7 is installed in C:\tomcat7 (because in program files I need admin right which is annoying because of the UAC in windows 8). my souce base dir is "C:\git\servletbook\ch1". The full path to the java file is C:\git\servletbook\ch1\src\com\examples\Ch1Servlet.java

My development environment

OS: Windows 8.1
Servlet Container: Apache Tomcat/7.0.57
JVM Version used by Tomcat: 1.7.0_71-b14
javac -version: javac 1.7.0_71

If you need to know anything else please ask

Its somehow strange but it seems that it was a problem with the encoding of the web.xml.
To trace down what actualy causes the problem I placed my class file inside the tomcat examples. To verify if this works. After this has worked, I copied the web.xml of the example project to my application and removed everything what I didn't need, and ... it worked. I changed the web.xml to have the same content as before and ... it still works. If I use a web.xml which I create by my self with Notepad++ it stops working. Maybe because of the default encoding using window-1251. But I also tried before to change the encoding to ISO-8859-1 in Notepad++, and this didn't help. Its somehow strange. But however. As long as I copy the web.xml and don't create it Notepad++ keeps the encoding and everything works as expected.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic