关于struts2中action获取参数的三种方法

    public String add() throws Exception {
        // ------------------------------方法一:通过设置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是多此一举。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值