Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-31-2011, 12:12 PM   PM User | #1
adarshakb
Regular Coder

 
adarshakb's Avatar
 
Join Date: Jun 2009
Location: Silicon valley of india
Posts: 247
Thanks: 11
Thanked 1 Time in 1 Post
adarshakb has a little shameless behaviour in the past
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
__________________
Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.

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

Last edited by adarshakb; 01-31-2011 at 12:16 PM..
adarshakb is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:08 AM.


Advertisement
Log in to turn off these ads.