1 package com.mockobjects.examples.password; 2 3 import java.io.IOException ; 4 import javax.servlet.ServletException ; 5 import javax.servlet.ServletConfig ; 6 import javax.servlet.http.HttpServlet ; 7 import javax.servlet.http.HttpServletRequest ; 8 import javax.servlet.http.HttpServletResponse ; 9 10 public class ForgotPasswordServlet extends HttpServlet { 11 public static final String SENT_PARAM_NAME = "sent"; 12 public static final String EMAIL_FAILED_PARAM_NAME = "bademail"; 13 public static final String EMAIL_NOT_FOUND_PARAM_NAME = "noemail"; 14 public static final String EMAIL_PARAM = "email"; 15 16 private PasswordReminder passwordReminder; 17 18 public ForgotPasswordServlet(PasswordReminder aPasswordReminder) { 19 super(); 20 passwordReminder = aPasswordReminder; 21 } 22 23 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException , IOException { 24 String emailAddress = request.getParameter(EMAIL_PARAM); 25 26 try { 27 passwordReminder.sendReminder(emailAddress); 28 redirectFor(response, emailAddress); 29 } catch (NotFoundException e) { 30 throw new ServletException ("Password not found", e); 31 } 32 } 33 34 private void redirectFor(HttpServletResponse response, String emailAddress) throws IOException { 35 response.sendRedirect("sent_uri?" + EMAIL_PARAM + "=" + emailAddress); 36 } 37 38 } 39 | Popular Tags |