|
|
| 在webwork2的action里取request.getParameter参数 |
作者:
文章来源:
访问次数:96次
加入时间:2007年04月07日
|
|
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 用起来方便些
|
|
|