In struts2, an action transmits data between actions and an action to a jsp.
1. In Action, we often jump from this Action to another Action. In this case, we need to use redirect, redirect-action, chain,
WhereRedirect and redirect-action are redirection, Which is equivalent to the second request of the browser. The previous data will be lost, and all parameters, value stacks, and request attributes will be lost.Chain is the server forwarding action,User request parameters, value stacks, and session data of the source Action are assigned to the target Action, that is, the request parameter value stacks and sessions obtained by the source action can be obtained in the target action.
When we want to pass parameters between these two actions:
A. UseAdd "?" To the link Method. If you want to add parameters in the request process, you can use xx at the end of the request, just like passing a value through a hyperlink? Xx = xx to pass parameters.
For example:
/Manager/managerInfo/account. action? Parameter Name = parameter value
,
IfThe parameter value is not a fixed value and can be obtained using the OGNL expression $ {parameter value }.Note: The parameter value here must provide the get/set Method in the corresponding Action. Otherwise, the parameter value cannot be obtained. Of course, a property value of an object can also be obtained here: $ {object name. attribute name}, which complies with the ONGL expression access rules and has been written in the previous article.
B,Use the child element form.
action2
${param1}
${param2}
Note:
1. If param1 and param2 are two variables, they must have their getter and setter in both actions.
2. If param1 is a constant, as long as there is a getter of param1 in action1, there must be getter and setter of param1 in action2
If you directly jump between two actions without passing parameters, the struts. xml file can be the same as above, but it does not have the param tag. You can also use the following Configuration:
action2.action
You can.
2. The parameter passed by struts2 action to the jsp page
A. On the jsp page, you can use the ONGL expression to access the value stack in the action.
B. You can use request. setAttribute (key, value); session. setAttribute (key, value); you can use the OGNL expression "# request. key "" # session. key.