我的Struts项目结构如下:
page1
-> action1
-> page2
-> action2
->page3
我需要的是我在输入标签中输入的值,page1
以便在action2
.
这是我的代码:
第 1 页:
<div class = "container">
<s:form id = "idinput" method = "post" action = "idEntered">
Enter id: <input id = "txtid" name = "txtid" type = "text" />
<input id = "cmdsubmit" name = "cmdsubmit" type = "submit" value = "enter details" />
</s:form>
</div>
行动1:
public class AddId extends ActionSupport {
private int txtid;
//getter and setter
@Override
public String execute() throws Exception {
return "success";
}
}
第2页:
<div class = "container">
<s:form id = "formvalues" method = "post" action = "formEntered">
<p>Your id entered is: <s:property value = "txtid" /></p>
First name: <input id = "txtfname" name = "txtfname" type = "text" />
Last name: <input id = "txtlname" name = "txtlname" type = "text" />
Age: <input id = "txtage" name = "txtage" type = "text" />
<input id = "cmdform" name = "cmdform" type = "submit" value = "submit form" />
</s:form>
</div>
行动2:
public class AddForm extends ActionSupport {
private String txtfname;
private String txtlname;
private int txtage;
private int txtid;
//getters and setters
@Override
public String execute() throws Exception {
return "success";
}
}
并显示所有内容
第 3 页:
<div class = "container">
ID: <s:property value = "txtid" /><br>
first name: <s:property value = "txtfname" /><br>
last name: <s:property value = "txtlname" /><br>
age: <s:property value = "txtage" />
</div>
这是我面临的问题,如txtid
显示为null
,从中我推断该值未从传递page2
到action2
我想出的一个解决方案是使用
<s:hidden value = "%{txtid}" name = "txtid2 />
在我的形式中page2
,我可以使用txtid
as txtid2
in的值action2
,但这似乎更像是一种 hack,而不是实际的解决方案,所以欢迎任何其他建议。