Reputation: 89
I have an action class where I am passing value from jsp, then modifying that value in action class 1 and then due to action chain, another action2 is being called. In action 2 I am getting the original value
value= 100// in jsp
action 1: value*10= 1000// action 1
go to action 2
I want modified value to go to action 2 i.e. 1000//
value modified in action 1. but I am getting10// i.e. original value.
can you tell me what to do in order to use values obtained from action 1.
struts.xml
<action name="action1" class="vaannila.action.action1">
<result name="success" type="chain">action2
</result>
</action>
<action name="action2" class="vaannila.action.action2">
<result name="success" type="dispatcher">result.jsp
</result>
</action>
action 1
public class action1 extends ActionSupport implements SessionAware{
public String execute() throws Exception{
System.out.println("original"+ pSB.getvalue() ); // getting 10
pSB.getvalue((pSB.getvalue()*10));
System.out.println("modified"+ pSB.getvalue() ); // getting 100
return "success";
}
}
action 2:
public class action2 extends ActionSupport implements SessionAware{
public String execute() throws Exception{
System.out.println("original"+ pSB.getvalue() ); // getting 10 instead of 100.
return "success";
}
}
Upvotes: 0
Views: 1557
Reputation: 855
change the action 1 as follows
public class action1 extends ActionSupport implements SessionAware{
public String execute() throws Exception{
System.out.println("original"+ pSB.getvalue() ); // getting 10
pSB.setvalue((pSB.getvalue()*10));
System.out.println("modified"+ pSB.getvalue() ); // getting 100
return "success";
}
the mistake is that you have calculated the value in the action1 class but did not updated it back to session
Upvotes: 1