问题
我使用jsp
提交表单,而struts 2
操作类负责处理。如果有问题,那么我将结果发送到同一页面并显示错误消息。
除了错误消息,我还想显示他在提交请求时提供的属性值。
源代码
表单包含少量文本字段和少量file
类型输入。
我的CreateRequest.jsp
文件:
<input type="file" name="attachment" id="myFile1" />
<input type="file" name="attachment" id="myFile2" />
<input type="file" name="attachment" id="myFile3" />
<input type="text" name="operationName" id="operation1" />
<input type="text" name="operationName" id="operation2" />
<input type="text" name="operationName" id="operation3" />
我的行动课程:
public class CreateRequest extends ActionSupport {
private List<File> attachment;
private List<String> attachmentContentType;
private List<String> attachmentFileName;
private List<String> operationName
// contains getter and setter for each property
public string execute(){
// some logic
//returns error if it fails otherwise success
}
}
struts.xml(Action Servlet)文件:
<action name="createRequest"
class="action.CreateRequest">
<result name="success">RequestStatus.jsp
</result>
<result name="input" >CreateRequest.jsp</result>
<result name="error" >CreateRequest.jsp</result>
</action>
帮助
当动作类返回错误时,如何获取CreateRequest.jsp
页面中显示的所有值。
答案 0 :(得分:1)
将ognl value=" %{operationName[0]}"
用于文本框