Instance: Now, a parameter named username is passed to the action on the jsp page.
Url: http: // localhost: 8080/StudentSystem/role_list.action? Username = 1321312
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); // result 1321312
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 = 1321312 & username = 34343
String [] username = reqeust. getParameterValues ("username"); // String Array
System. out. println (username); // result 1321312
System. out. println (username [0]); // The result is 1321312.
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 1321312.
From: Black e's column