Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder adarshakb's Avatar
    Join Date
    Jun 2009
    Location
    Silicon valley of india
    Posts
    247
    Thanks
    11
    Thanked 1 Time in 1 Post

    Tomcat servlet not running

    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.
    Code:
    // 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>" );
          out.close();
       }
    }
    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
    Last edited by adarshakb; 01-31-2011 at 01:16 PM.
    Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.

    Albert Einstein
    -----------------------------------------------------
    My Blog songs


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •