• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot run servlets in Tomcat

 
X V Jay
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I have been unable to run servlet using Tomcat 4.1.27. I have put the
class file in WEB-INF\classes. Please tell me where did I go wrong ?
Thank you
X V Jay

Here is the source....
=====================================================
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>");
}
}
================================================================
Here is the web.xml
=================================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<servlet>
<servlet-name>TestingServlet</servlet-name>
<servlet-class>TestingServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestingServlet</servlet-name>
<url-pattern>/TestingServlet</url-pattern>
</servlet-mapping>
</web-app>
=======================================================================
Error message generated....
======================================================================
HTTP Status 404 - /myJspApps/servlet/TestingServlet
----------------------------------------------------------------------
type Status report
message /myJspApps/servlet/TestingServlet
description The requested resource (/myJspApps/servlet/TestingServlet)
is not available.

-----------------------------------------------------------------------
Apache Tomcat/4.1.27
=====================================================================
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have made an explicit mapping for your servlet in your web.xml, so you don't need the "/servlet" in your URL. Try something like:
/myJspApps/TestingServlet
 
X V Jay
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Frank. It worked.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"X V Jay"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it
here.
Thanks! and welcome to the JavaRanch!
Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic