public String add() throws Exception {
// ------------------------------方法一:通过设置get与set方法来获取参数
System.out.println(this.username);
// ------------------------------方法二:通过request对象来获取参数
/*
* public class SupperAction extends ActionSupport implements
*/
System.out.println(this.getRequest().getParameter("username"));
// ------------------------------方法三:通过ActionContext对象来获取参数
// **import com.opensymphony.xwork2.ActionContext;
String[] username = (String[]) this.getContext().getParameters().get("username");
System.out.println(username[0] + username.length);
return "success";
// ------------------------------方法一:通过设置get与set方法来获取参数
System.out.println(this.username);
// ------------------------------方法二:通过request对象来获取参数
/*
* public class SupperAction extends ActionSupport implements
* ServletRequestAware{
*private HttpServletRequest request;
* private HttpSession session;
* private Application application;
* private ActionContext context;这是SupportAction,所有的子类action extends该父类,得到所有对象*/
System.out.println(this.getRequest().getParameter("username"));
// ------------------------------方法三:通过ActionContext对象来获取参数
// **import com.opensymphony.xwork2.ActionContext;
String[] username = (String[]) this.getContext().getParameters().get("username");
System.out.println(username[0] + username.length);
return "success";
}
有些博文写到在Context.getParameters();后转换成Map,本人表示不解,转换成Map后再去获取参数,这时候就没有get(“参数名”)这样一个方法了。个人愚见 :觉得转换成map是多此一举。