1, the browser to the action pass parameters:
set the property in action and set the Get/set method for the property. Assign a value by the name of the property when passing the parameter. such as Xxx?name=aa
value with Request.getprameters ("property name");
public class Useraction {
private String name;
private user user;
Public String Useradd () {
System.out.print (User.getname ());
System.out.print (name);
Return "Success";
}
Public String GetName () {return
name;
}
public void SetName (String name) {
this.name = name;
}
Public User GetUser () {return
user;
}
public void SetUser (user user) {
this.user = user
}
}
Note: Struts2 does not use the single case mode, so each request is a new object.
2, Action to the browser interface pass parameters:
There are three kinds of ways:
1) Species: directly to the action attribute (there is a Get/set method) assignment, JSP in <s:property value= "OGNL expression"/> Value, note that the return result type is forward
For example: <s:property value= "name"/> <s:property value= "User.Name"/>
2: Pass the value by Actioncontext, add in the method called in the action:
Actioncontext.getcontext (). Put ("Key", "value");
<s:property value= "#key"/> value in JSP
3) Kinds: Through request, session pass value. The action method sets the value by obtaining the HttpServletRequest, HttpSession, and map objects.
For example:
Servletactioncontext.getrequest (). setattribute ("arg0", "value"); Servletactioncontext.getrequest (). GetSession (). setattribute ("arg0", "value"); Actioncontext.getcontext (). GetSession (). Put ("Key", "value");
JSP page through:
"Transferred from" http://cailangwei.blog.163.com/blog/static/131458579201287112552485/