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">
I believe you have two options to solve this problem:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.