天天看點

Struts2中的ActionContext.getContext().getParameters()

struts2中的action已經脫離的request,是用getxxx()來取送出過來的參數,如果在寫程式的時候特定需要自己來取parameter可以通過以下兩種方法實作。第一種用actioncontext類,所有的參數都從這裡actioncontext.getcontext().getparameters()取他傳回的是一個map類型。

map param= actioncontext.getcontext().getparameters();

若有一個送出過來的username,那麼通過param.get("username")可以取值。值得注意的是param.get("username")是一個string數組,struts就是這樣設計的。既然是string數組就需要這樣取值:

string value[] = (string[])param.get("username");

string username = "";

for(int i=0;i<value.length;i++)

{

 username +=value[i];

}

第二種方法是直接把request引用進來

servletactioncontext.getrequest().getparameter("username")

原帖位址:http://www.jspcn.net/htmlnews/11500549785621702.html