FileDocCategorySizeDatePackage
NewsletterServlet.javaAPI DocExample1849Wed Aug 07 19:26:20 BST 2002com.oreilly.javaxp.httpunit

NewsletterServlet

public class NewsletterServlet extends HttpServlet
Newsletter subscription servlet. This servlet delegates to a JSP for page rendering.
author
Eric M. Burke
version
$Id: NewsletterServlet.java,v 1.1 2002/08/08 00:26:21 jepc Exp $

Fields Summary
Constructors Summary
Methods Summary
private voiddispatchToSubscriptionPage(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)

        RequestDispatcher dispatcher =
                req.getRequestDispatcher("subscription.jsp");

        dispatcher.forward(req, res);
    
protected voiddoGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)

        dispatchToSubscriptionPage(req, res);
    
protected voiddoPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)

        if (req.getParameter("subscribeBtn") != null) {
            handleSubscribeButton(req, res);
        } else if (req.getParameter("unsubscribeBtn") != null) {
            // @todo - handle this
        }
        dispatchToSubscriptionPage(req, res);

    
private voidhandleSubscribeButton(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)

        String name = req.getParameter("nameField");
        String email = req.getParameter("emailField");

        // email is required
        if (email == null || email.trim().length() == 0) {
            req.setAttribute("errorMessage",
                    "Email address is required");
            dispatchToSubscriptionPage(req, res);
        } else {
            // @todo - subscribe the user!
        }