servlet not working

Hello

My servlets are not working.Iam using Tomcat 5.0

The environment variables that I have set are:

CLASSPATH D:\j2sdk1.4.2_13\jre\lib\rt.jar;D:\j2sdk1.4D:\j2sdkee1.3.1\lib\j2ee.jar

JAVA_HOME

D:\j2sdk1.4.2_13

J2EE_HOME

D:\j2sdkee1.3.1

TOMCAT_HOME

D:\Tomcat 5.0\bin

My application is in: D:\Tomcat 5.0\webapps\ROOT\greeting

GreetingServlet.class

D:\Tomcat 5.0\webapps\ROOT\greeting\WEB-INF\classes\myServlet\

Java file

package myServlet;

import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

import java.util.*;

public class GreetingServlet extends HttpServlet

{

protected void gopost(HttpServletRequest req,HttpServletResponse res)

throws ServletException,IOException

{

String name=req.getParameter("name");

String email=req.getParameter("email");

String msg=null;

GregorianCalendar calendar = new GregorianCalendar();

if(calendar.get(calendar.AM_PM) == calendar.AM)

{

msg = "Good Morning";

}

msg="Good Afternoon";

res.setContentType("text/html");

PrintWriter out = res.getWriter();

out.println("<HTML>");

out.println("<BODY>");

out.println("<P>"+msg+", "+name+"</P>");

out.println("<P>Thanks for registering your email ("+email+") with us.<P>");

out.println("<P>The Projava team</P>");

out.println("</BODY>");

out.println("</HTML>");

out.close();

}

}

html file

D:\Tomcat 5.0\webapps\ROOT\greeting\

<HTML>

<HEAD>

<TITLE>PROJAVA REGISTRATION</TITLE>

</HEAD>

<BODY>

<H1>Welcome</H1>

<FORM ACTION="/greeting/servlet/GreetingServlet" METHOD="POST">

<P>Your name <INPUT TYPE="text" SIZE="40" NAME="name"></P>

<P>Your email <INPUT TYPE="text" SIZE="40" NAME="email"></P>

<INPUT TYPE="submit" VALUE="SUBMIT"></P>

</FORM>

</BODY>

<HTML>

web.xml

D:\Tomcat 5.0\webapps\ROOT\greeting\WEB-INF

<?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>Registration</servlet-name>

<servlet-class>myServlet.GreetingServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>GreetingServlet</servlet-name>

<url-pattern>/greeting/servlet/GreetingServlet</url-pattern>

</servlet-mapping>

</web-app>

When I type this in the browser

http://localhost:8080/greeting/index1.html

and click the Submit button I get this message

message /greeting/servlet/GreetingServlet

description The requested resource (/greeting/servlet/GreetingServlet) is not available.

The URL is http://localhost:8080/greeting/servlet/GreetingServlet

Please help me out

Thanks

[3296 byte] By [suddena] at [2007-11-26 22:18:40]
# 1

<web-app>

<servlet>

<servlet-name>Registration</servlet-name>

<servlet-class>myServlet.GreetingServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>GreetingServlet</servlet-name>

<url-pattern>/greeting/servlet/GreetingServlet</url-pattern>

</servlet-mapping>

</web-app>

The servlet-name in the servlet-mapping must match a servlet-name in the servlet definitions.

try :

<web-app>

<servlet>

<servlet-name>Registration</servlet-name>

<servlet-class>myServlet.GreetingServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>Registration</servlet-name>

<url-pattern>/greeting/servlet/GreetingServlet</url-pattern>

</servlet-mapping>

</web-app>

tolmanka at 2007-7-10 11:13:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Thank you for replying

I tried what you suggested but its still not working

I uncommented

<servlet>

<servlet-name>invoker</servlet-name>

<servlet-class>

org.apache.catalina.servlets.InvokerServlet

</servlet-class>

.............................

and

<servlet-mapping>

<servlet-name>invoker</servlet-name>

<url-pattern>/servlet/*</url-pattern>

</servlet-mapping>

in conf/web.xml

servlet didn't work. The message is the same resource not available

Iam not sure whether I have set environment variables properly

Please tell me where Iam wrong

Thank you

suddena at 2007-7-10 11:13:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Post your current web.xml file
tolmanka at 2007-7-10 11:13:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE web-app

web.xml

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>Registration</servlet-name>

<servlet-class>myServlet.GreetingServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>Registration</servlet-name>

<url-pattern>/greeting/servlet/GreetingServlet</url-pattern>

</servlet-mapping>

</web-app>

suddena at 2007-7-10 11:13:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
The doPost method in your servlet is named goPost:protected void gopostRodneyM
RodneyDMa at 2007-7-10 11:13:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Thank youI corrected it but its still not working.Is it a classpath issue.Do I have to include something else in the classpath
suddena at 2007-7-10 11:13:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
you have typed like thisWhen I type this in the browser http://localhost:8080/greeting/index1.html but you need to mention your root directory in url like http://localhost:8080/root/greeting/index1.html
eswar071a at 2007-7-10 11:13:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

First of all, I would like to ask a question to all, is it only a WEB-INF folder in each application in webapps folder will be looked by Tomcat. For example, a web application with following - \webapps\greeting\WEB-INF\greeting2\WEB-INF hierarchy is invalid right? because the WEB-INF folder has appear twice, anyway, Tomcat will only look into the upper level of WEB-INF folder which is in \webapps\greeting\WEB-INF, am I right?

Hi sudden,

I would like to suggest my solution to your question which I assumed you have correct the mistake pointed out by tolmank and RodneyDM.

1) We should take the classess folder include its content from D:\Tomcat 5.0\webapps\ROOT\greeting\WEB-INF\ to D:\Tomcat 5.0\webapps\ROOT\WEB-INF\.

2) Copy the <servlet>

<servlet-name>Registration</servlet-name>

<servlet-class>myServlet.GreetingServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>GreetingServlet</servlet-name>

<url-pattern>/greeting/servlet/GreetingServlet</url-pattern>

</servlet-mapping>

of D:\Tomcat 5.0\webapps\ROOT\greeting\WEB-INF\web.xml to be included in the whatever existing content of D:\Tomcat 5.0\webapps\ROOT\WEB-INF\web.xml

3) Amend <FORM ACTION="/greeting/servlet/GreetingServlet" METHOD="GET">

of D:\Tomcat 5.0\webapps\ROOT\greeting\index1.html to <FORM ACTION="../GreetingServlet" METHOD="GET">

cneiruca at 2007-7-10 11:13:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...