获取参数值以生成图表
用户输入两个日期 它需要单击一个按钮...
如果日期有效,则调用相同的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将它们作为视图中图像 URL 的参数传递,如下所示:
You need to pass them as parameters of image URL in your view, like this: