Struts 1使用Multipart / Form-Data Enctype进行失败的表单验证后丢失请求参数 [英] Struts 1 Losing Request Parameters after Failed Form Validation with Multipart/Form-Data Enctype

查看:163
本文介绍了Struts 1使用Multipart / Form-Data Enctype进行失败的表单验证后丢失请求参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Struts表单。它有一些文本字段和一个文件字段。我的表单上的
enctype multipart / form-data 。我验证了 actionform
validate方法。如果文本字段为空,则返回需要
的错误。与可见字段一起,我传递一些隐藏字段,当处理表单并返回到
JSP时,需要
作为请求参数。 JSP需要这些请求 params

I have a simple Struts form. It has a few text fields and a file field. The enctype is multipart/form-data on my form. I validate in the actionform's validate method. If the text fields are empty, I return errors that they are required. Along with the visible fields, I pass a few hidden fields that are needed as request params when the form is processed and returned to the JSP. The JSP needs these request params.

当没有验证错误时,一切都很好,因为请求
params 使用操作中的 ActionRedirect 类。但如果
返回错误,我将丢失请求 params 。 (我可以在 actionform 验证方法或操作中访问

Everything works great when there are no validation errors as the request params get returned by using the ActionRedirect class in the action. But if there are errors returned, I lose the request params. (I am able to access them in the actionform validate method or in the action).

如何在<$ c中验证错误时确认请求 params 返回
$ c> multipart 表格?是否有任何解决方法?

How can I make sure the request params are passed back upon validation error in multipart form? Is there any sort of workaround?

动作映射(对于模糊处理稍作编辑)如下:

Action-mappings (slightly edited for obfuscation) below:

   <action
    path="/saveQuestion"
    type="blahblahblah.QuestionAction"
    parameter="save"
    name="QuestionForm"
    input="populateQuestion.do"
    scope="request"
    validate="true">
    <set-property property="cancellable" value="true"/>
    <forward name="success" path="viewSurvey.do" redirect="true"/>
  </action>
  <action
    path="populateQuestion"
    type="blahblahblah.QuestionAction"
    parameter="populateRequest"
    name="ItemForm"
    scope="request">
      <forward name="success" path=".editing.Question"/>
  </action>

我的JSP表格行:

<html:form styleId="QuestionForm" action="/saveQuestion" enctype="multipart/form-data" method="POST">


推荐答案

我相信你有两种方法可以解决这个问题:

I believe you have two options to solve this problem:


  • 将范围更改为会话:这样,数据将存储在会话中,您不会丢失任何数据。

  • 实现验证的重置方法:这样,在验证中调用reset方法时,可以重新填充表单的数据。

我希望这会有所帮助。我可能在我的旧代码文件中有一些其他建议,但我现在无法访问它们。如果我有时间,我会稍后检查出来。

I hope this helps somehow. I might have some other suggestions in my old code files, but i don't have access to them right now. If I have time I'll check them out later.

这篇关于Struts 1使用Multipart / Form-Data Enctype进行失败的表单验证后丢失请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆