Instance: Now, a parameter named username is passed to the action on the JSP page.
URL: http: // localhost: 8080/studentsystem/role_list.action? Username = qk12333.com
1. Get it through the Get Set Method
Define a variable with the same name in the corresponding action class and generate the set get method. Then, the parameter automatically obtains the value.
String username;
Public String GetUserName ()
{
Return username;
}
Public void setusername (string username)
{
This. Username = username;
}
System. Out. println (username); // The result is qk12333.com.
2. Use servletactioncontext to get // import org. Apache. struts2.servletactioncontext;
Httpservletrequest reqeust = servletactioncontext. getrequest ();
String username = reqeust. getparameter ("username"); // string
// URL: http: /localhost: 8080/studentsystem/role_list.action? Username = qk12333.com & username = qk12333.com
String [] username = reqeust. getparametervalues ("username"); // String Array
System. Out. println (username); // The result is qk12333.com.
System. Out. println (username [0]); // The result is qk12333.com.
3. Use actioncontext to get // import com. opensymphony. xwork2.actioncontext;
Actioncontext context = actioncontext. getcontext ();
Map Params = context. getparameters ();
String [] username = (string []) Params. Get ("username ");
// Actioncontext obtains an object such as object or string []
System. Out. println (username [0]); // The result is qk12333.com.