webwork的action已經(jīng)脫離的request,是用getXxx()來(lái)取提交過(guò)來(lái)的參數(shù)
如果在寫程序的時(shí)候特定需要自己來(lái)取Parameter可以通過(guò)以下兩種方法實(shí)現(xiàn)
第一種用ActionContext類,所有的參數(shù)都從這里ActionContext.getContext().getParameters()取
他返回的是一個(gè)Map類型
Map param= ActionContext.getContext().getParameters();
如果有一個(gè)提交過(guò)來(lái)的username
那就可以這樣寫
param.get("username");不過(guò)這里要注意一下param.get("username")是一個(gè)String數(shù)組(為什么要返回?cái)?shù)據(jù)我也不知道,我從weblogic窗口看到param.get("username")被out出來(lái)Ljava.lang.String,忙活了半天)
String value[] = (String[])param.get("username");
String username = "";
for(int i=0;i<value.length;i++)
{
username +=value[i];
}
這樣就可以得到正確的username了
第二種方法是直接把request引用進(jìn)來(lái)
ServletActionContext.getRequest().getParameter("username")
ServletActionContext.getRequest()就是httpservletrequest
這個(gè)類再import com.opensymphony.webwork.ServletActionContext
用起來(lái)方便些