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

泄露秘密 提交于 2019-12-22 20:27:31

问题


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.

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).

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>

And my JSP form line:

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

回答1:


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.

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.



来源:https://stackoverflow.com/questions/14241354/struts-1-losing-request-parameters-after-failed-form-validation-with-multipart-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!