1 22 23 package org.jboss.tutorial.web; 24 25 import javax.servlet.http.HttpServletRequest ; 26 import javax.servlet.http.HttpServletResponse ; 27 28 import org.jboss.tutorial.ee.service.Horoscope; 29 import org.jboss.tutorial.ee.service.Randomizer; 30 import org.springframework.web.bind.ServletRequestUtils; 31 import org.springframework.web.servlet.ModelAndView; 32 import org.springframework.web.servlet.mvc.multiaction.MultiActionController; 33 34 37 public class AppController extends MultiActionController 38 { 39 40 private Randomizer randomizer; 41 private Horoscope horoscope; 42 43 public Randomizer getRandomizer() 44 { 45 return randomizer; 46 } 47 48 public void setRandomizer(Randomizer randomizer) 49 { 50 this.randomizer = randomizer; 51 } 52 53 public Horoscope getHoroscope() 54 { 55 return horoscope; 56 } 57 58 public void setHoroscope(Horoscope horoscope) 59 { 60 this.horoscope = horoscope; 61 } 62 63 public ModelAndView numberHandler(HttpServletRequest request, HttpServletResponse response) 64 throws Exception 65 { 66 int radius = ServletRequestUtils.getRequiredIntParameter(request, "radius"); 67 return new ModelAndView("main", "number", randomizer.getNumber(radius)); 68 } 69 70 public ModelAndView wordHandler(HttpServletRequest request, HttpServletResponse response) 71 throws Exception 72 { 73 return new ModelAndView("main", "word", randomizer.getWord()); 74 } 75 76 public ModelAndView horoscopeHandler(HttpServletRequest request, HttpServletResponse response) 77 throws Exception 78 { 79 if (ServletRequestUtils.getStringParameter(request, "clear") != null) 80 { 81 horoscope.clear(); 82 return new ModelAndView("main"); 83 } 84 else 85 { 86 int month = ServletRequestUtils.getRequiredIntParameter(request, "month"); 87 return new ModelAndView("main", "horoscope", horoscope.getHoroscope(month)); 88 } 89 } 90 91 } 92 | Popular Tags |