Head first jsp. chapter 1 help

so this is driving me crazy. I’ve been trying to get this to work for hours and it’s something so simple.

  1. I have XAMPP installed with the tomcat plugin.
  2. http://127.0.0.1:8080/ works
  3. my tomcat manager list doesn’t display my application… does it need to? http://127.0.0.1:8080/manager/html/list

okay so in chapter 1, I made a directory structure like so…

tomcat > webapps > ch1 > WEB-INF > classes

WEB-INF contains web.xml which looks like:


<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">
<servlet>
<servlet-name>Chapter1 Servlet</servlet-name>
<servlet-class>Ch1Servlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Chapter1 Servlet</servlet-name>
<url-pattern>/Serv1</url-pattern>
</servlet-mapping>
</web-app> 

the classes folder in WEB-INF contains the class file of

Ch1Servlet.java



import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class Ch1Servlet extends HttpServlet{
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException{
		PrintWriter out = response.getWriter();
		java.util.Date today = new java.util.Date();
		out.println("<html><body><h1 align=center>HF\\'s Chapter1 Servlet</h1><br>"+today+"</body></html>");
	}
}

when I go to: http://127.0.0.1:8080/ch1/Serv1

I get this error: HTTP Status 503 - This application is not currently available

anyone have any idea on how to fix it?

Wish I could help but it seems like everything is correct. Try this

  1. remove all files+directory under $Tomcat/webapps. Do not remove the webapps directory itself, just the files+directory under it.
  2. remove all files + directory under $Tomcat/work
  3. create a directory “ch1” under webapps.
  4. create a directory “WEB-INF” under “ch1”
  5. create a directory “classes” under “WEB-INF”
  6. copy and paste Ch1Servlet.class in “classes”
  7. copy and paste web.xml under “WEB-INF”

Hope it works but I can 100% tell you that your code is fine. Worst case is download new tomcat server and see if that helps.

hmm that didn’t work :frowning:

i can’t help you with your problem, sorry…

i just wanted to say how curious it is that you would come to sitepoint forums to ask questions about the content of a book that sitepoint didn’t publish, when there exists another forum by the actual publisher of the book

that says a lot about how good sitepoint is

:wink:

haha. good point. sitepoint has great forums.

well I have somewhat narrowed it down. It turns out that once it fails to load the servlet once, I can never load it again for some reason. I end up having to make a new application. Everything works up until I start adding stuff to the web.xml file. Removing the stuff I added does not fix the problem.

going to http://127.0.0.1:8080/manager/html/

mentions that the application in question has stopped running. When I try to “start” it. it fails and give this message:

FAIL - Application at context path /testing could not be started

at this point I can’t even go to index.html that located in the application’s folder. what’s going on?

Instead of using the manager to start and stop your applications, I would recommend fully starting and stopping tomcat between changes in your code or your web.xml.

I haven’t had very good luck using the manager application.

Yeah with Tomcat I generally do everything by hand, and definitely restart the server after making any changes to any xml files.

I don’t think it’s curious at all. There are a lot of good publishers out there, and having run out of .NET books, I read widely. But no one else has put the effort into building their community the way sitepoint has. Staff members on the boards and a whole system of mentors, team leaders, award winners, etc., etc. It makes sure that new visitors have a lot of good leads for who they can go to for topical questions which makes you feel that little bit more comfortable. Sitepoint is my favorite web development forum.

dear chronic, thanks for the support for sitepoint forums

“Whatever you can do or dream you can, begin it.”

for what it’s worth, the head first series has closer to the appropriate number of superfluous illustrations (a non-zero number) than sitepoint books, although on the wrong side of the number, so according to the rules of the price is right, sitepoint wins