2014-10-20 42 views
0

动态添加的表值我有类似下面的我的JSP文件:获取的servlet

<table> 
<tr class="schedule"> 
    <td><input type="text" name="fromDate"</td> 
    <td><input type="text" name="toDate"</td> 
    <td> 
     <table> 
      <tr class="fromTime"> 
       <td> 
        <input type="text" name="fromHour"/> 
       </td> 
      </tr> 
     </table> 
    </td> 
    <td> 
     <table> 
      <tr class="toTime"> 
       <td> 
        <input name="toTime"/> 
       </td> 
      </tr> 
     </table> 
    </td> 
    <td> 
     <table> 
      <tr> 
       <td> 
        <input name="amount"/> 
       </td> 
      </tr> 
     </table> 
    </td> 
</tr> 
<tr class="totalAmount"> 
    <td><input type="text" class="totAmount"</td> 
<tr> 
</table> 

时间表行获得动态添加和每个这个,可以有节数FROMTIME到时间表。我需要在我的servlet中获取这些值。我知道我可以通过

String[] fromDates=request.getParameterValues("fromDate"); 
String[] toDates=request.getParameterValues("toDate"); 

我找得到没有fromdateTODATE的值,找出我如何可以检索fromHourtoHour值对应其没有fromdateTODATE

谢谢,提前。

+0

你的表单标签在哪里? – Jason 2014-10-20 11:15:57

+0

对不起,HTML部分应该在表单标签内。我只写了相关部分@Jason – 2014-10-20 11:36:17

回答

0

当他们创建动态,让他们看起来像"fromDate_1""toDate_1" 和对应的时间样子"fromTime_1""to_time_1"
那么接下来的调度看起来像"fromDate_2""toDate_2" 和对应的时间看起来像"fromTime_2""to_time_2"
和如此等等

然后在你的servlet中 做一个for循环让它们像

for (int i=1;i<100;i++){ //i dont think so the max value will be larger than 100 
if (request.getParameterValues("fromDate_"+i)==null){ 
break; 
}else{ 
fromDate[i]=request.getParameterValues("fromDate_"+i); 
} 
} 

和你所拥有的每个参数相同

+0

这似乎是做这种必要的一种粗糙的方式。有没有一个标准的方法来做同样的事情? – 2014-10-20 11:38:00