Hi,
I am trying to run my first
servlet using Apache
Tomcat 4.1.24.
I've bought a book on
J2EE solutions and followed the instructions exactly but I can't get my servlet to run.
This is my servlet code, which I have compiled in C:\Java\tomcat\webapps\myApp\WEB-INF\classes:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class TestingServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>Servlet
Testing</TITLE>");
out.println("</HEAD>");
out.println("<BODY>");
out.println("Welcome to the Servlet Testing Center");
out.println("</BODY>");
out.println("</HTML>");
}
}
My web.xml file which I have put in C:\Java\tomcat\webapps\myApp\WEB-INF is as follows:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>Testing</servlet-name>
<servlet-class>TestingServlet</servlet-class>
</servlet>
</web-app>
I have also edited the server.xml file (in C:\Java\tomcat\conf) and added the following:
<Context path="/myapp" docBase="webapps/myapp" debug="0" reloadable="true">
</Context>
Now according to the book I'm following (
Java for the Web with Servlets,
JSP, and EJB: A Developer's Guide to J2EE Solutions - Bundi Kurniawan, New Riders Publishing 2002) I should be able to view the servlet at the following URL:
http://localhost:8080/myapp/servlet/Testing However I get a 404 error : The requested resource (/myapp/servlet/Testing) is not available.
I have tried moving my servlet to C:\Java\tomcat\webapps\examples\WEB-INF\classes and viewing it at
http://localhost:8080/examples/servlet/TestingServlet and it works fine.
I don't really want to do all my development in the examples directory, so I'd like to find a solution as to why it doesn't work in the myapp directory.
Can anybody see the problem? Any suggestions would be much appreciated!