0
用戶輸入兩個日期 它需要點擊一個按鈕...得到參數值的方式來生成圖表
如果日期是有效的,同樣的jsp頁面被稱爲有的值在請求中設置好的。 。在本JSP,如果setSeachDone爲真,圖表是產生...
另一servled控制器被要求的圖像...但在該請求已經設置好的值是空
@Controller
@RequestMapping("/statError")
public class StatisticError {
@Autowired
private IUserService userService;
@InitBinder("statisticForm")
protected void initBinder(WebDataBinder binder) {
binder.setValidator(new StatisticErrorFormValidator());
}
@RequestMapping(method = RequestMethod.GET)
public String statistic(Model model) {
StatisticErrorForm statisticForm = new StatisticErrorForm();
model.addAttribute("statisticForm", statisticForm);
return "statisticError";
}
@RequestMapping(method = RequestMethod.POST)
public String statistiqueResult(@Valid @ModelAttribute StatisticErrorForm statisticForm, BindingResult result, ModelMap model, HttpServletRequest request,
HttpServletResponse response) {
if (!result.hasFieldErrors() && !result.hasErrors()) {
request.setAttribute("startDate", statisticForm.getStartDate());
request.setAttribute("endDate", statisticForm.getEndDate());
statisticForm.setSearchDone(true);
}
model.addAttribute(statisticForm);
return "statisticError";
}
}
servlet的控制器
@Controller
@RequestMapping("/statError.jpg")
public class ImageErrorController {
@Autowired
private IUserService userService;
@RequestMapping(method = RequestMethod.GET)
public void generateChart(HttpServletRequest request,
HttpServletResponse response) {
if (request.getAttribute("startDate") != null && request.getAttribute("endDate") != null) {
response.setContentType("image/jpg");
AxisChart axisChart = userService.generateChart();
ServletEncoderHelper.encodeJPEG(axisChart, 1.0f, response);
}
}
是有辦法通過發送用戶對imageErrorController輸入的值? 添加模型generateChart?
確定我試過了,但request.getAttribute(「的startDate」)仍然是空 – redfox26 2011-03-29 07:54:37
與工作要求.getParameter – redfox26 2011-03-29 08:06:04