| Author |
Tomcat 404 error
|
Niamh Gill
Greenhorn
Joined: Jan 30, 2003
Posts: 8
|
|
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!
|
 |
Leonildo Campos
Ranch Hand
Joined: Jun 02, 2003
Posts: 33
|
|
Hi, Try cut off the comments regarding **The mapping for the invoker servlet** in file $TOMCAT_HOME/conf/web.xml (it has the default parameters for all servlets if you don't have your web.xml for each Context. Leonildo
|
"Put yourself on view. This brings your talents to light."<br />Leonildo Campos<br />SCJP 1.4<br />SCWCD
|
 |
Saket Barve
Ranch Hand
Joined: Dec 19, 2002
Posts: 224
|
|
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>
I think the docBase ought to be just myapp and not webapps/myapp.
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>
Add this after you close the servlet tag and before you close the web-app tag. Make sure you shutdown (if already running) and restart the tomcat server after making the changes. Saket
|
 |
Niamh Gill
Greenhorn
Joined: Jan 30, 2003
Posts: 8
|
|
Thanks for your help guys. I changed my web.xml file in myApp to look like this: <?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>TestingServlet</servlet-name> <servlet-class>TestingServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>TestingServlet</servlet-name> <url-pattern>/servlet/Testing</url-pattern> </servlet-mapping> </web-app> This solved the problem! Thanks again.
|
 |
 |
|
|
subject: Tomcat 404 error
|
|
|