I'm Using Ubuntu 8.10...:
Trying to figure out why I can't seem to fix the Status 404 error with Tomcat. I can see the other servlet samples working in the Tomcat Sample website. The webserver appears to be working, but when I try to run my servlet from the index.html page in my greeting directory, it just doesn't work. Any help would be appreciated. I put all of the $path and other info below as well as the html, java and web.xml info below.
*** I did compile the java file in the right directory I believe with the following command while in the $TOMCAT_HOME/webapps/greeting/src directory...:
javac -classpath $CLASSPATH/servlet-api.jar -d ../WEB-INF/classes *.java
Name of servlet I'm trying to call after hitting the submit button on the index.html page...:
http://localhost:8080/greeting/servlet/GreetingServlet
echo $PATH
/usr/lib/jvm/java-6-sun/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/var/lib/tomcat6/lib:/usr/share/tomcat6
echo $JAVA_HOME...:
/usr/lib/jvm/java-6-sun
echo $TOMCAT_HOME...:
/var/lib/tomcat6
echo $CLASSPATH...:
/var/lib/tomcat6/lib
echo $CATALINA_HOME...:
/usr/share/tomcat6
Here is the index.html...:
<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">
<INPUT TYPE="submit" VALUE="Submit"></P>
</FORM>
</BODY>
</HTML>
Ok Here is my 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 alias -->
<servlet-name>GreetingServlet</servlet-name>
<!-- Fully qualified Servlet class -->
<servlet-class>GreetingServlet</servlet-class>
</servlet>
</web-app>
Here is the GreetingServlet.java file...:
// Import Servlet packages
import javax.servlet.*;
import javax.servlet.http.*;
// Import other Java packages
import java.io.*;
import java.util.*;
public class GreetingServlet extends HttpServlet {
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
// Get parameters from the request.
String name = request.getParameter("name");
String email = request.getParameter("email");
// Compute a greeting message
String message = null;
GregorianCalendar calendar = new GregorianCalendar();
if(calendar.get(Calendar.AM_PM) == Calendar.AM) {
message = "Good Morning";
}
else {
message = "Good Afternoon";
}
// Set MIME type for the response
response.setContentType("text/html");
// Obtain a print writer object
PrintWriter out = response.getWriter();
// Write the content
out.println("<HTML>");
out.println("<BODY>");
out.println("<P>" + message + ", " + name + "</P>");
out.println("<P> Thanks for registering your email (" + email +
") with us.</P>");
out.println("<P> - The Pro Java Team. </P>");
out.println("</BODY>");
out.println("</HTML>");
out.close();
}
}