[英]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: 我相信您可以通过两种方法解决此问题:
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.