LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 12-19-2008, 12:23 PM   #1
rtoney5
Member
 
Registered: Oct 2007
Location: FL, US
Distribution: Ubuntu MintLinux-XFCE, Mint7, Parted Magic, PCOS OpenWorkstation, OpenSuse-11
Posts: 131

Rep: Reputation: 17
Question The dreaded status 404 error on Tomcat...


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();
}
}

Last edited by rtoney5; 12-19-2008 at 12:24 PM. Reason: Added "I'm Using Ubuntu 8.10..."
 
Old 12-19-2008, 01:37 PM   #2
rtoney5
Member
 
Registered: Oct 2007
Location: FL, US
Distribution: Ubuntu MintLinux-XFCE, Mint7, Parted Magic, PCOS OpenWorkstation, OpenSuse-11
Posts: 131

Original Poster
Rep: Reputation: 17
Smile Mystery to the Status 404 has been solved...

Hope this helps someone else.
Looks like I've solved my own mystery. I needed to add the <servlet-mapping>
tag code in BOLD RED below to my web.xml file. In particular, remember to put the /servlet/ in front of the servlet name's <url-patter> tag. I'm finally on my way to creating websites using Java Servlets.... Yaaayyyyy



<?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>

<servlet-mapping>
<servlet-name>GreetingServlet</servlet-name>
<url-pattern>/servlet/GreetingServlet</url-pattern>
</servlet-mapping>


</web-app>

Last edited by rtoney5; 12-19-2008 at 01:40 PM. Reason: Decided to paste in the comple web.xml contents for whoever needs it...
 
Old 12-19-2008, 02:23 PM   #3
AuroraCA
Member
 
Registered: Jul 2008
Location: Northern CA USA
Distribution: Ubuntu, Slackware, Gentoo, Fedora, Red Hat, Puppy Linux
Posts: 370

Rep: Reputation: 35
Thank you for posting your followup solution

Thank you for posting a solution to you problem. This was an interesting problem and I was preparing to respond and lo and behold you resolved it yourself.

I appreciate your consideration of other members and guests with your followup. Not all posters are as considerate as to post the final resolution for the benefit of others.

Sorry I could have not been quicker in responding.

Last edited by AuroraCA; 12-19-2008 at 02:24 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Server-status (mod_status) not working - keep getting 404 Not Found. Zippy1970 Linux - Server 2 09-28-2008 09:31 AM
404 error using JSP on tomcat jayn16 Programming 2 06-25-2006 01:07 PM
Tomcat Status 404 issue FirmbIT Linux - Software 18 04-22-2006 10:30 AM
tomcat jsp examples 404 treycarroll Linux - Software 1 04-21-2006 07:57 PM
gmplayer and the dreaded -vo error cyris Linux - Software 18 03-28-2003 09:58 AM


All times are GMT -5. The time now is 03:21 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration