Instance: Now the JSP page passes a parameter named username to the action
Url:http://localhost:8080/studentsystem/role_list.action?username=qk12333.com
first, the Get Set method is used to obtain
Define a variable with the same name in the corresponding action class and generate a set get method, then the parameter will automatically fetch the value
String username;
Public String GetUserName ()
{
return username;
}
public void Setusername (String username)
{
This.username = Username;
}
SYSTEM.OUT.PRINTLN (username)//result is qk12333.com
second, through Servletactioncontext get/import imports Org.apache.struts2.ServletActionContext;
HttpServletRequest reqeust= servletactioncontext.getrequest ();
String Username=reqeust.getparameter ("username");//Strings
Url:http://localhost:8080/studentsystem/role_list.action?username=qk12333.com&username=qk12333.com
String[] Username=reqeust.getparametervalues ("username");//Array of strings
SYSTEM.OUT.PRINTLN (username)//result is qk12333.com System.out.println (username[0));//result is qk12333.com
third, through Actioncontext get/import imports Com.opensymphony.xwork2.ActionContext;
Actioncontext context = Actioncontext.getcontext ();
Map params = Context.getparameters ();
String[] Username= (string[]) params.get ("username");
Actioncontext gets to an object such as objects or string[] System.out.println (username[0);//The result is qk12333.com