KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mockobjects > examples > dynamic > SimpleServlet


1 package com.mockobjects.examples.dynamic;
2
3 import java.io.*;
4
5 import javax.servlet.*;
6 import javax.servlet.http.*;
7
8 /**
9  * @author dev
10  */

11
12 public class SimpleServlet extends HttpServlet {
13
14     private Timer timer;
15     private MailSender mailSender;
16
17     public SimpleServlet(Timer aTimer, MailSender aMailSender) {
18         super();
19         timer = aTimer;
20         mailSender = aMailSender;
21     }
22     
23     public SimpleServlet() {
24          this(null,null); // really this would be a proper timer and mail sender...
25
}
26
27     public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
28                 
29         String JavaDoc body = request.getParameter("body");
30         String JavaDoc subject = request.getParameter("subject");
31         String JavaDoc[] recipients = request.getParameterValues("recipients");
32         String JavaDoc browser = request.getParameter("browser-identifier");
33         
34         // Cause a failure by calling something unexpected
35
//String pet = request.getParameter("favourite-pet");
36

37         int age = request.getIntHeader("age");
38         response.setContentType("text/html");
39         PrintWriter writer = response.getWriter();
40         
41         writer.print("timer before:" + timer.getTime());
42         mailSender.sendMail(subject, recipients, body);
43         writer.print("timer after:" + timer.getTime());
44         
45     }
46
47 }
48
Popular Tags