This is the servlet code:
package com.example.web;
import com.example.model.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class BeerSelect extends HttpServlet{
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("Beer Selection Advice<br>");
String c = req.getParameter("COLOR");
BeerExpert be = new BeerExpert();
List result = be.getBrands(c);
req.setAttribute("styles", result);
RequestDispatcher view = req.getRequestDispatcher("result.jsp");
view.forward(req, res);
}
}
And this is my DD:
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsl="http://www.w3.org/2001/XMLSchema-instance"
xsl:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<security-constraint>
<web-resource-collection>
<url-pattern>/SelectBeer.do</url-pattern>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>member</role-name>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<security-role>
<role-name>member</role-name>
<role-name>guest</role-name>
</security-role>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/loginPage.html</form-login-page>
<form-error-page>/loginError.html</form-error-page>
</form-login-config>
</login-config>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/errorPage.jsp</location>
</error-page>
<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>
<context-param>
<param-name>mainEmail</param-name>
<param-value>
main@abc.com</param-value>
</context-param>
</web-app>
And this is my loginPage.html:
<html><body>
Please login:
<form method="POST" action="j_security_check">
<input type="text" name="j_username">
<input type="password" name="j_password">
<input type="submit" value="Enter">
</form>
</body></html>