View Full Version : Tomcat servlet not running

01-31-2011, 12:12 PM
Hi, I just setup tomcat and it comes up properly when i run localhost:8080 in the browser with the propr startup page for server when its started.

But when i put a servlet's .class file in WEB-INF/classes director(case sensitive as it is) and run it in http://localhost:8080/servlet/HelloServlet it doesnt run. It gives a 404 error

Here is my java code.. it compiles properly and it creates the .class file also.

// A Hello, World Servlet example.
// Written 3/2001 by Wayne Pollock, Tampa Florida USA.

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

public class HelloServlet extends HttpServlet
public void doPost ( HttpServletRequest req, HttpServletResponse res )
throws IOException, ServletException
doGet( req, res );

public void doGet ( HttpServletRequest req, HttpServletResponse res )
throws IOException, ServletException
res.setContentType( "text/html" ); // Can also use "text/plain" or others.
PrintWriter out = res.getWriter();

// Get the requestor's IP address (See JavaDocs to see how to get other info):
String addr = req.getRemoteAddr();

// Create output (the response):
out.println( "<HTML><HEAD><TITLE>HelloServlet in myServletWAR</TITLE></HEAD>" );
out.println( "<BODY><H1 ALIGN=\"CENTER\">" );
out.println( "Hello " + addr + ", from HelloServlet in myServletWAR!" );
out.println( "</H1></BODY></HTML>" );

PS: I tested a simple jsp file to display date and time and it works. I have put the HelloServlet.class in the WEB-INF/classes directory