model: /** * */ package com.example.model; import java.util.ArrayList; import java.util.List; /** * @author 2172980000502 * */ public class BeerExpert { public List<String> getBrands(String colorValue) { List<String> brands = new ArrayList<String>(); if ("1".equals(colorValue)) { brands.add("b1"); brands.add("b2"); } else if ("2".equals(colorValue)) { brands.add("b3"); brands.add("b4"); } else if ("3".equals(colorValue)) { brands.add("b5"); brands.add("b6"); } else if ("4".equals(colorValue)) { brands.add("b7"); brands.add("b8"); } return brands; } } servlet: package com.example.web; import java.io.IOException; import java.io.PrintWriter; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.example.model.BeerExpert; public class BeerSelect extends HttpServlet { /** * */ private static final long serialVersionUID = 1L; /** * Constructor of the object. */ public BeerSelect() { super(); System.out.println("in Constructor of BeerSelect."); } /** * Destruction of the servlet. <br> */ public void destroy() { super.destroy(); // Just puts "destroy" string in log // Put your code here System.out.println("in destroy of Constructor."); } /** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to * post. * * @param request * the request send by the client to the server * @param response * the response send by the server to the client * @throws ServletException * if an error occurred * @throws IOException * if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("int doPost of Constructor."); response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.print("beer selection advice<br>"); String colorValue = request.getParameter("color"); BeerExpert be = new BeerExpert(); List<String> result = be.getBrands(colorValue); for (String string : result) { out.print("<br>try : " + string); } } /** * Initialization of the servlet. <br> * * @throws ServletException * if an error occurs */ public void init() throws ServletException { // Put your code here System.out.println("in init of Constructor."); } } html: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>forml.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <!--<link rel="stylesheet" type="text/css" href="./styles.css" mce_href="styles.css">--> </head> <body> <h1> beer selection page </h1> <br> <form method="post" action="SelectBeer.do" name="beerForm"> <p> select beer characteristics </p> <p> <select name="color" size="1"> <option value="1"> light </option> <option value="2"> amber </option> <option value="3"> brown </option> <option value="4"> dark </option> </select> </p> <p> <input type="submit" value="submit" name="submit"> </p> <p> </p> <p> </p> <p> </p> </form> </body> </html> web.xml: <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <description>BeerSelect</description> <display-name>BeerSelect</display-name> <servlet-name>BeerSelect</servlet-name> <servlet-class>com.example.web.BeerSelect</servlet-class> </servlet> <servlet-mapping> <servlet-name>BeerSelect</servlet-name> <url-pattern>/SelectBeer.do</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>form.html</welcome-file> </welcome-file-list> </web-app>