NewsletterServletpublic class NewsletterServlet extends HttpServlet Newsletter subscription servlet. This servlet delegates to a JSP
for page rendering. |
Methods Summary |
---|
private void | dispatchToSubscriptionPage(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
RequestDispatcher dispatcher =
req.getRequestDispatcher("subscription.jsp");
dispatcher.forward(req, res);
| protected void | doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
dispatchToSubscriptionPage(req, res);
| protected void | doPost(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 void | handleSubscribeButton(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!
}
|
|