Spring Jsps 和跳转到锚点
我想知道 Spring 中是否有某种方法可以在控制器中指定我希望将客户端发送到我用于视图的 .jsp 页面中的特定锚点。
我的 .jsp 页面中有一个部分,由 #errors
锚点标识,用于显示发生的任何表单错误。每当我需要在模型验证失败后将它们发送回 .jsp 时,我希望能够将它们直接发送到该锚点。
在我的控制器类中,我处理验证错误,如下所示:
if (result.hasErrors())
{
for (ObjectError error : result.getAllErrors())
{
logger.debug("Validation Error: " + error.getDefaultMessage());
}
ModelAndView mv = new ModelAndView();
mv.setViewName("/secure/formViews/newAdminBookingMenu");
mv.addObject(BindingResult.MODEL_KEY_PREFIX + "booking", result);
return mv;
}
我希望能够在该代码块中指定,当客户端获取渲染的 newAdminBookingMenu.jsp
返回时,它们将直接发送到 <该页面内的 code>#errors 锚标记。
显然,我不能通过仅将 #errors
添加到我希望呈现的 .jsp 的名称来做到这一点,因为 InternalResourceViewResolver 会将视图解释为 /WEB-INF/jsp/jspName#errors。 jsp
这显然是不正确的。
我知道这可以通过 javascript 和 onload 事件来完成,但我发现这种方式很脏,并且真的宁愿找到一种 Spring 方法(如果存在)。
有什么想法吗?
干杯。
I was wondering if there is some way in Spring to specify in the controller that I would like to send the client to a specific anchor within the .jsp page that I am using for my view.
I have a section in my .jsp page, identified by an #errors
anchor, that displays any form errors that occur. I would like to be able to send them directly to that anchor whenever I need to send them back to the .jsp after model validation fails.
Inside my controller classes, I handle validation errors like so:
if (result.hasErrors())
{
for (ObjectError error : result.getAllErrors())
{
logger.debug("Validation Error: " + error.getDefaultMessage());
}
ModelAndView mv = new ModelAndView();
mv.setViewName("/secure/formViews/newAdminBookingMenu");
mv.addObject(BindingResult.MODEL_KEY_PREFIX + "booking", result);
return mv;
}
I would like to be able to specify in that code block that when the client gets the rendered newAdminBookingMenu.jsp
back that they are sent directly to the #errors
anchor tag within that page.
I obviously cannot do this by just adding #errors
to the name of the .jsp i wish to render as the InternalResourceViewResolver will interpret the view as /WEB-INF/jsp/jspName#errors.jsp
which is clearly incorrect.
I know this can be accomplished with javascript and the onload
event but I find that kind of dirty and would really rather find a Spring approach if one exists.
Any ideas?
Cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许
RedirectView
是一个选项:参考:
Perhaps a
RedirectView
is an option:Reference: