简体   繁体   English

具有Multipart / Form-Data Enctype的表单验证失败后,Struts 1丢失请求参数

[英]Struts 1 Losing Request Parameters after Failed Form Validation with Multipart/Form-Data Enctype

I have a simple Struts form. 我有一个简单的Struts表单。 It has a few text fields and a file field. 它具有几个文本字段和一个文件字段。 The enctype is multipart/form-data on my form. enctype是我表单上的multipart/form-data I validate in the actionform 's validate method. 我在actionform的validate方法中进行验证。 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. 与可见字段一起,我传递了一些隐藏字段,这些表单在处理表单并返回给JSP时作为请求参数而需要。 The JSP needs these request params . JSP需要这些请求params

Everything works great when there are no validation errors as the request params get returned by using the ActionRedirect class in the action. 当没有验证错误时,一切都很好,因为在操作中使用ActionRedirect类可以返回请求params But if there are errors returned, I lose the request params . 但是,如果返回错误,我将丢失请求params (I am able to access them in the actionform validate method or in the action). (我可以在actionform验证方法或action中访问它们)。

How can I make sure the request params are passed back upon validation error in multipart form? 如何确保在验证错误时以multipart形式返回请求params 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>

And my JSP form line: 而我的JSP表格行:

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

I believe you have two options to solve this problem: 我相信您可以通过两种方法解决此问题:

  • Change the scope to session: This way the data will be stored in session and you won't lose any data. 将范围更改为会话:这样,数据将存储在会话中,并且您不会丢失任何数据。
  • Implement the reset method of your validation: This way, when the reset method is called in your validation, you can repopulate the data of the form. 实现验证的reset方法:这样,当在验证中调用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. 如果有时间,我稍后再检查。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 enctype=&quot;multipart/form-data&quot; 请求不起作用之后 - after enctype="multipart/form-data" request not working 尽管我写了“enctype=&quot;multipart/form-data”,但发生错误“当前请求不是多部分请求” - Although I wrote 'enctype="multipart/form-data', ERROR 'Current request is not a multipart request' happen enctype multipart/form-data 在多数据类型表单中的使用 - Usage of enctype multipart/form-data in multi data type form 如何在同一个jsp页面中查看jsp表单请求提交? (ENCTYPE =“多部分/格式数据”) - How can i check jsp form request submit in same jsp page? (enctype=“multipart/form-data”) h:form enctype =“ multipart / form-data”不执行任何操作 - h:form enctype=“multipart/form-data” not firing any action 使用 enctype=&quot;multipart/form-data&quot; 时请求 getParameter 始终为 null - request getParameter is always null when using enctype="multipart/form-data" enctype =“ multipart / form-data”破坏了我的应用 - enctype=“multipart/form-data” destroyed my app 使用enctype =“ multipart / form-data”将选定的图像获取到控制器类吗? - Get selected image to Controller Class with enctype=“multipart/form-data”? 了解Spring MVC中的enctype = multipart / form-data的工作 - Understanding working of enctype = multipart/form-data in spring mvc 当提交的表单具有属性 enctype=&quot;multipart/form-data&quot; 时,如何在控制器中获取表单数据? - How to get form data in controller when the form that was submitted has the attribute enctype="multipart/form-data"?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM