1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package sample.contact;
17
18 import org.springframework.beans.factory.InitializingBean;
19
20 import org.springframework.web.servlet.ModelAndView;
21 import org.springframework.web.servlet.mvc.Controller;
22 import org.springframework.util.Assert;
23
24 import java.io.IOException;
25
26 import javax.servlet.ServletException;
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
29
30
31 /***
32 * Controller for public index page (default web app home page).
33 *
34 * @author Ben Alex
35 * @version $Id: PublicIndexController.java,v 1.3 2005/04/15 01:21:32 luke_t Exp $
36 */
37 public class PublicIndexController implements Controller, InitializingBean {
38
39
40 private ContactManager contactManager;
41
42
43
44 public void setContactManager(ContactManager contact) {
45 this.contactManager = contact;
46 }
47
48 public ContactManager getContactManager() {
49 return contactManager;
50 }
51
52 public void afterPropertiesSet() throws Exception {
53 Assert.notNull(contactManager, "A ContactManager implementation is required");
54 }
55
56 public ModelAndView handleRequest(HttpServletRequest request,
57 HttpServletResponse response) throws ServletException, IOException {
58 Contact rnd = contactManager.getRandomContact();
59
60 return new ModelAndView("hello", "contact", rnd);
61 }
62 }