Chris Greenleaf

Greenhorn
+ Follow
since Aug 08, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Chris Greenleaf

There's no reference to my BeerSelect servlet in any of the log files. The funny thing is the servlet in the first chapter works fine. The only difference in this one is that I'm using a package and doing a form action which I think it can't find. The code compiled fine but I think it just can't find the servlet.

What's the best way to debug this?
12 years ago
I still can't get this to work. I understand the context path shouldn't be hard coded but I'm new to servlets and trying to do an example in the Head First Servlets book. I changed my form.html to the following and I still can't get this to work:





I've also tried the following:


This is frustrating.
12 years ago
I assume you mean the context path in the form.html?

So, should the context path be:

"http://localhost:8080/BeerV1/SelectBeer.do"

Thanks,
Chris
12 years ago
I'm trying to get a servlet to work and I'm having some issues. I have the following form.html in the C:\tomcat\webapps\Beer-v1\ directory:

<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 value="light"> light </option>
<option value="amber"> amber </option>
<option value="brown"> brown </option>
<option value="dark"> dark </option>
</select>
<br><br>
<center>
<input type="SUBMIT">
</center>
</form></body></html>

I have the following DD (web.xml) file in the following directory: C:\tomcat\webapps\Beer-v1\WEB-INF\ directory:

<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 my source 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, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Beer Selection Advice<br>");
String c = request.getParameter("color");
out.println("<br>Go beer color " +c);
}
}

I put the BeerSelect.class file in the following directory:

C:\tomcat\webapps\Beer-v1\WEB-INF\classes\com\example\web\ directory.

When I bring up the URL http://localhost:8080/Beer-v1/form.html my page displays correctly but when I click on the submit button the servlet doesn't work. I suspect it can't find it but I can't figure out what I'm doing wrong.

I've installed tomcat in the C:\tomcat directory.

Any Ideas why this isn't working?




12 years ago