Code of servlet:
package com.example.web;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class BeerSelect extends HttpServlet{
public void doPost(HttpServletResponse response,
HttpServletRequest request)
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>Got beer color " + c);
}
}
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>
html
<html><body>
<h1 align = "center">Beer Selection Page</h1>
<form method = "POST" action = "SelectBeer.do">
Select beer characteristics
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>