在控制器之间传递表单反馈以重新显示表单错误消息时出现问题 [英] Problems passing form feedback between controllers to re-display a form error message
问题描述
控制器A显示一些数据并显示一个表单.
Controller A shows some data and displays a form.
该表单提交给控制器B.
The form submits to Controller B.
在控制器B中发现表单错误时,需要由控制器A重新显示该表单.
When form errors are found in Controller B, the form needs to be re-displayed by Controller A.
要执行此操作,需要在控制器A中添加return redirect "blah"
.
To do this requires a return redirect "blah"
in Controller A.
要使用重定向将错误传递回控制器A,我可以在模型中设置错误消息:
To pass the errors back to Controller A using a redirect, I can set the error message in the model:
model.put("errormsg", "look what happened");
这具有将错误消息的整个文本放入URL中的烦人作用:
This has the annoying effect of putting the entire text of the error message into the URL:
/controllera/somemethod?errormsg=look+what+happened
但是,即使我在URL上看到了文本,当我尝试从JSTL中显示该文本时,也没有显示任何内容:
However, even though I see the text on the URL, when I try to display it from the JSTL, nothing is shown:
<c:out value="${errormsg}"/>
是否有更好的方法来解决所有这些问题?
Is there a better approach to all of this?
推荐答案
是否有更好的方法来解决所有这些问题?
Is there a better approach to all of this?
恕我直言,更好的方法是使用标准方案:控制器A显示表单,将数据提交给控制器A,如果发生错误,则控制器A显示错误.如果数据有效的控制器A确实重定向到控制器B.
IMHO better approach is to use standard scheme: controller A shows form, data submitted to controller A and if error occurs controller A display errors. If data valid controller A do redirect to controller B.
这篇关于在控制器之间传递表单反馈以重新显示表单错误消息时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!