java - Spring MVC 一个表单将数据提供给另一个表单

标签 java spring-mvc

我的开始问题是这个错误消息:

Problem accessing /segment.htm. Reason:

Neither BindingResult nor plain target object for bean name

'acceptCorrected' available as request attribute

我正在做的事情的顶级描述是这样的:

Form1 请求用户输入一些信息。当 form1 提交时,我需要通过一些处理推送该数据,然后呈现包含处理结果的 form2。我试图通过 form1 Controller 的 onSubmit 返回的模型将 form1 的结果传达给 form2。

reason相信这是禁止的。

但是,如果是的话,如何在呈现 form2 的 JSP 页面时使 1 中的数据可用?

<bean name="/segment.htm" class="com.basistech.rseharvest.SegmentFormController">
  <property name="sessionForm" value="true"/>
  <property name="commandName" value="segment"/>
  <property name="commandClass" value="com.basistech.rseharvest.Segment"/>
  <property name="validator">
   <bean class="com.basistech.rseharvest.SegmentValidator"/>
  </property>
  <property name="formView" value="segment"/>
  <property name="successView" value="showSegmented"/>
  <property name="segmenter" ref="segmenter"/>
 </bean>

 <!--  the page to enter text -->
 <bean name="/showSegmented.htm" class="com.basistech.rseharvest.AcceptCorrectedFormController">
  <property name="sessionForm" value="true"/>
  <property name="commandName" value="acceptCorrected"/>
  <property name="commandClass" value="com.basistech.rseharvest.AcceptCorrected"/>
  <property name="validator">
   <bean class="com.basistech.rseharvest.CorrectionsValidator"/>
  </property>
  <property name="formView" value="showSegmented"/>
  <property name="successView" value="segment"/>
  <property name="data" ref="data"/>
 </bean>

最佳答案

The onSubmit of the first form returns a ModelAndView pointing to the second form, by naming the same view as you see as the formView of the second form.

您能进一步解释一下这意味着什么吗?是呈现 HTML 的“段” View ,其中包含 <form>发布到 /showSegmented.htm

formBackingObject()仅在初始 GET 上被调用向页面请求。

你想要/segmented.htm显示表单和 /showSegmented.htm处理输入值?

如果是这样,这实际上并不是 AbstractFormController 的预期用途。 。此类旨在用于以下情况:您希望同一个 Controller 处理 1) 表单的呈现和 2) 表单提交的处理。

关于java - Spring MVC 一个表单将数据提供给另一个表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3168324/

相关文章:

java - Spring Web MVC 本地化显示日语错误

java - 我应该使用公共(public)访问还是包访问?为什么我应该对字段使用 private?

java - 快速排序中的枢轴数

spring-mvc - 在 Tomcat 上部署多个 WAR

spring - 将 Spring Web MVC 应用程序部署为域根中的网站

触发了 hibernate 实体拦截器但设置值不保存

java - 使用 Javax.comm 重新枚举 java 中的所有串行设备

Java - 使用 Gson 序列化 Iterable<Map.Entry<>>

java mysql 磁盘已满

java - Spring MVC webapp链接到excel文档并重命名