壹、通過get set方法獲取
在對應的action類中定義同名變量,並生成set get方法,那麽參數將會自動獲取值
String username;
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
System.out.println(username);//結果為1321312
二、通過ServletActionContext獲取//導入import org.apache.struts2.ServletActionContext;
HttpServletRequest reqeust= ServletActionContext.getRequest();
String username=reqeust.getParameter("username");//字符串
//url:
String[] username=reqeust.getParameterValues("username");//字符串數組
System.out.println(username);//結果為1321312
System.out.println(username[0]);//結果為1321312
三、通過ActionContext獲取//導入import com.opensymphony.xwork2.ActionContext;
ActionContext context = ActionContext.getContext();
Map params = context.getParameters();
String[] username=(String[])params.get("username");
//ActionContext獲取到壹個對象如object或String[]
System.out.println(username[0]);//結果為1321312