FileDocCategorySizeDatePackage
ListController.javaAPI DocExample1925Sat Nov 22 13:13:08 GMT 2003fcexample.controller

ListController

public class ListController extends HttpServlet
A simple implementation of a servlet-based controller, using the MailingBean model from the model package.

Fields Summary
public static final String
FIRST_PARAM
public static final String
LAST_PARAM
public static final String
EMAIL_PARAM
public static final String
MAILINGBEAN_ATTR
Constructors Summary
Methods Summary
protected voiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Respond to an HTTP GET request.

    
                   
        
                          
          
    
        // read the paremeters from the request
        String first = request.getParameter(FIRST_PARAM);
        String last = request.getParameter(LAST_PARAM);
        String email = request.getParameter(EMAIL_PARAM);
        
        // get the mailing list bean for this list
        MailingBean mb = MailingBeanFactory.newInstance();
       
        // set the parameters into the bean
        mb.setFirst(first);
        mb.setLast(last);
        mb.setEmail(email);
       
        // store a copy of the bean in the request context
        request.setAttribute(MAILINGBEAN_ATTR, mb);
        
        // perform the business method
        boolean result = mb.doSubscribe();
      
        // choose a page based on the result
        String nextPage = "/success.jsp";
        if (!result) nextPage = "/failure.jsp";
       
        // transfer control to the selected view
        RequestDispatcher dispatcher = 
            getServletContext().getRequestDispatcher(nextPage);
        dispatcher.forward(request, response);