<input name="text1"></input>
<input name="text2"></input>
<input name="text3"></input>
...
...
...form表单提交后,actionform里如何设置get set这些text1-3 因为text条数可变 可能3条可能5条
<input name="text2"></input>
<input name="text3"></input>
...
...
...form表单提交后,actionform里如何设置get set这些text1-3 因为text条数可变 可能3条可能5条
try...{
String name;
Enumeration pNames=request.getParameterNames();
while(pNames.hasMoreElements())...{
name=(String)pNames.nextElement();
out.print(name+"="+request.getParameter(name));
}
}catch(Exception e)...{
out.print(e.toString());
}字段个数不确定,你怎么写actionForm?
private String[] text;<input name="text">
<input name="text">
<input name="text">
j2ee api中说明的
getParameterNames
public java.util.Enumeration getParameterNames()Returns an Enumeration of String objects containing the names of the parameters contained in this request. If the request has no parameters, the method returns an empty Enumeration.
不过最好还是页面用js组装成一个值。action里面再去拆。
struts就应该用ActionForm或者其子类,然后用struts的标签标示表单元素<html:text property="name" />你说到是动态的,那就就用DynamicActionForm吧
return text;
}
public void setText(String[] text) {
this.text = text;
}
然后getText()报错的!
我是说用ActionForm接收,但我的<input name=text1> <input name=text2> <input name=text3>...个数不定 我在Form中怎么set它?
form中set?你的set方法就用自动生成的,对值进行set是在jsp中如果要在Form的set方法里面来做数据的修改,还是定义成String数组吧,轮循数组去修改值。。
<input name="text">
<input name="text">用getParameterNames,一个循环,凡是text打头的拿出来呗。
不过最好还是页面用js组装成一个值。action里面再去拆。 最后用getParameterNames 比较方便