I have got a little problem with Struts2, and I don't know why it doesn't work ...
I want to pass 2 variables between two JSP, via an Action class :
view1.jsp :
<s:form action="myAction">
<input id="var1" name="var1" type="text" />
<input id="var2" name="var2" type="text" />
<button type="submit"> Ok </button>
</s:form>
-> var1 and var2 are the variables that I want to pass to the Action class
struts.xml:
<action name="myAction" class="MyAction" method="execute">
<result name="success">view2.jsp</result>
</action>
Action.java :
public class MyAction extends DefaultActionSupport
{
private String var1;
private String var2;
public String execute() throws Exception
{
// ... Some actions ...
return SUCCESS;
}
// Getters & Setters for var1 and var2 (generated by Eclipse)
public String getVar1()
{
return var1;
}
public void setVar1(String var1)
{
this.var1 = var1;
}
public String getVar2()
{
return var2;
}
public void setVar2(String var2)
{
this.var2 = var2;
}
-> This works correctly ; if I put "System.out.print" with the getters, it shows me the good values of var1 (content1) and var2 (content2)
view2.jsp :
Values of var1 = <s:property value="var1" />
Values of var2 = <s:property value="var2" />
Textfield with var1 in default-value : <s:textfield value="%{var1}" />
Textfield with var2 in default-value : <s:textfield value="%{var2}" />
-> There is a problem here :
I can't get the content of var1 and var2 !
-> <s:property value="var1" />
and <s:textfield value="%{var1}
are returning "null"
Where is my error ? I don't understand ... I followed what the others said on the internet ...
Thank you !