`
leon1509
  • 浏览: 533304 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

在webwork2的action里取request.getParameter参数

阅读更多
webwork的action已经脱离的request,是用getXxx()来取提交过来的参数
如果在写程序的时候特定需要自己来取Parameter可以通过以下两种方法实现

第一种用ActionContext类,所有的参数都从这里ActionContext.getContext().getParameters()取
他返回的是一个Map类型
Map param= ActionContext.getContext().getParameters();

如果有一个提交过来的username,那就可以这样写

param.get("username");

不过这里要注意一下param.get("username")是一个String数组(为什么要返回数组我也不知道,我从weblogic窗口看到param.get("username")被out出来Ljava.lang.String,忙活了半天)
  String value[] = (String[])param.get("username");
  String username = "";
  for(int i=0;i<value.length;i++){
   username +=value[i];
  }


这样就可以得到正确的username了

第二种方法是直接把request引用进来

ServletActionContext.getRequest().getParameter("username")
ServletActionContext.getRequest()就是httpservletrequest
这个类再import com.opensymphony.webwork.ServletActionContext
用起来方便些
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics