Servlets 获取参数值以生成图表

Servlets 获取参数值以生成图表,servlets,spring-mvc,httpresponse,Servlets,Spring Mvc,Httpresponse,用户输入两个日期 它需要点击一个按钮 如果日期有效,则调用相同的jsp页面,并在请求中设置一些值。。。在这个jsp中,如果setSeachDone为true,则生成一个图表 为映像调用另一个servled控制器。。。但是请求中已经设置的值为空 @Controller @RequestMapping("/statError") public class StatisticError { @Autowired private IUserService userService; @InitBind

用户输入两个日期 它需要点击一个按钮

如果日期有效,则调用相同的jsp页面,并在请求中设置一些值。。。在这个jsp中,如果setSeachDone为true,则生成一个图表

为映像调用另一个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?

您需要在视图中将它们作为图像URL的参数传递,如下所示:

<img src = "<c:url value = "/statError.jpg">
        <c:param name = "startDate" value = "${startDate}" />
        <c:param name = "endDate" value = "${endDate}" />
    </c:url>" />

" />

ok我试过了,但request.getAttribute(“startDate”)仍然为空