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")
本文详细介绍了在Struts2框架中通过ActionContext类和直接引用request获取提交参数的方法,包括如何从Map类型参数中提取字符串数组并转换为单一字符串。
627

被折叠的 条评论
为什么被折叠?



