获取参数值以生成图表

发布于 2024-10-27 14:28:53 字数 1928 浏览 2 评论 0原文

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

如果日期有效,则调用相同的 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?

user enter two date
it need to click on a button...

if the date are valid, the same jsp page is called and some value are setted in the request... in this jsp, if setSeachDone is true, a chart is generate...

another servled controller is called for the image... but the value already setted in the request are empty

@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";
}

}

the servlet controller

@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);

    }

}

is there a way to send the value entered by the user to the imageErrorController?
add the model to generateChart?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

○闲身 2024-11-03 14:28:53

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

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

You need to pass them as parameters of image URL in your view, like this:

<img src = "<c:url value = "/statError.jpg">
        <c:param name = "startDate" value = "${startDate}" />
        <c:param name = "endDate" value = "${endDate}" />
    </c:url>" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文