struts 2动作错误:检索表单属性的值

时间:2013-10-10 13:56:48

标签: java forms jsp servlets struts2

问题

我使用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页面中显示的所有值。

1 个答案:

答案 0 :(得分:1)

将ognl value=" %{operationName[0]}"用于文本框