Forms 如何使用Struts从动态表单接收所有字段?
我发现自己有以下问题: 我有一个使用Forms 如何使用Struts从动态表单接收所有字段?,forms,dynamic,struts-1,Forms,Dynamic,Struts 1,我发现自己有以下问题: 我有一个使用logic:iterate生成的页面,显示服务的当前主管和助理。 该页面也可以作为一种形式,人们可以添加他们可能的替代品,但你永远不知道其中有多少 由于我目前使用的环境,它必须没有JSTL,所以很多选项都没有了;也无法使用DynaActionForm。因为我找不到任何东西,但我已经得到了答案,所以我决定创建此版本,以回答可能存在相同问题的任何人 代码: 公共ActionForward post(ActionMapping映射、ActionForm表单、Http
logic:iterate
生成的页面,显示服务的当前主管和助理。
该页面也可以作为一种形式,人们可以添加他们可能的替代品,但你永远不知道其中有多少
由于我目前使用的环境,它必须没有JSTL,所以很多选项都没有了;也无法使用
DynaActionForm
。因为我找不到任何东西,但我已经得到了答案,所以我决定创建此版本,以回答可能存在相同问题的任何人
代码:
公共ActionForward post(ActionMapping映射、ActionForm表单、HttpServletRequest请求、HttpServletResponse响应)引发异常{
字符串[]tot;
试试{
枚举字段form=request.getParameterNames();
while(fieldsForm.hasMoreElements()){
字符串当前=(字符串)fieldsForm.nextElement();
tot=request.getParameterValues(当前);
System.out.println(“字段名为:“+current”);
对于(i=0;i
public ActionForward post(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
String[] tot;
try {
Enumeration<?> fieldsForm = request.getParameterNames();
while(fieldsForm.hasMoreElements()) {
String current = (String) fieldsForm.nextElement();
tot = request.getParameterValues(current);
System.out.println("Field name is: " + current);
for (i=0; i<tot.length; i++) {
// do whatever you need to do; contents are in tot[i]
System.out.println("Value " + i + " is: " + tot[i]);
}
}
catch (Exception ex) {
ex.printStackTrace();
System.err.println(ex.getMessage());
}
}