Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HTTP 404 Servlets do not run Tomcat 5.0.

 
mallika arora
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying some examples from Head First Servlet book. I have J2SDK 1.4.2_13 installed with Tomcat 5.0. HTML page opens fine when I do http://localhost:8080/Beerv1/form1.html but when this HTML page calls Servlet, it gives HTTP status 404 error.

Here is what's in web.xml:

<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd" version="2.4">
<servlet>
<servlet-name>Ch3 Beer</servlet-name>
<servlet-class>com.example.web.BeerSelect</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Ch3 Beer</servlet-name>
<url-pattern>/SelectBeer.do</url-pattern>
</servlet-mapping>
</web-app>

Here is Servlet code:

package com.example.web;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class BeerSelect extends HttpServlet
{

public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("Beer Selection Advice<br>");
String c = request.getParameter("color");
out.println("<br>Got beer color" + c);
}
}


This is HTML page calling Servlet:

<html>
<body>
<h1 align="center">Beer Selection Page</h1>
<form method="POST" action="SelectBeer.do">Select beer characteristics<p>
Color:<select name="color" size="1"
<option>light
<option>amber
<option>brown
<option>dark
</select>
<br><br>
<center>
<input type="SUBMIT"
</center>
</form></body></html>


Please advice. Is there any Tomcat settings that need to be changed?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic