0
我在JSP頁面中有下面提到的代碼。我可以將以下文本框中的所有值保存到數據庫中。但是,我讀取了servlet中的每個文本框名稱(request.getParameter())以保存字段。有沒有可能改進這個代碼?例如:將一個特定列的所有值保存到數組中並保存到數據庫。如是;請展示一個可以幫助我的例子。還有如何忽略一行是否爲空。例如,用戶只填充兩行,其餘行爲空。我只想保存數據庫中的前兩行。改善代碼保存到DB
<table class="cmn-table" id="t1" border="1" style="margin-left: 0.2em; margin- right:0em">
<col width="5%">
<col width="18%">
<col width="18%">
<col width="18%">
<col width="18%">
<col width="18%">
<tr>
<th>Sl.No</th>
<th>Source IP Address</th>
<th>Destination IP Address</th>
<th>Service and Port (TCP, UDP, etc.)</th>
<th>Start Date</th>
<th>Expiration Date</th>
</tr>
<tr>
<td style="align:center"> 1 </td>
<td><input type="text" name="name" id="name" size="20"> </td>
<td><input type="text" name="name1" id="name1" size="20"> </td>
<td><input type="text" name="name2" id="name2" size="20"> </td>
<td><input type="text" name="name3" id="name3" size="15"> <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /></td>
<td><input type="text" name="name4" id="name4" size="15"><img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12')" /> </td>
</tr>
<tr>
<td style="align:center"> <label> 2 </label> </td>
<td><input type="text" name="name5" id="name" size="20"> </td>
<td><input type="text" name="name6" id="name" size="20"> </td>
<td><input type="text" name="name7" id="name" size="20"> </td>
<td><input type="text" name="name8" id="name3" size="15"> <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /></td>
<td><input type="text" name="name9" id="name4" size="15"><img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12')" /> </td>
</tr>
<tr>
<td> <label> 3 </label> </td>
<td><input type="text" name="name10" id="name" size="20"> </td>
<td><input type="text" name="name11" id="name" size="20"> </td>
<td><input type="text" name="name12" id="name" size="20"> </td>
<td><input type="text" name="name13" id="name3" size="15"> <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /></td>
<td><input type="text" name="name14" id="name4" size="15"><img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12')" /> </td>
</tr>
<tr>
<td> <label>4 </label> </td>
<td><input type="text" name="name15" id="name" size="20"> </td>
<td><input type="text" name="name16" id="name" size="20"> </td>
<td><input type="text" name="name17" id="name" size="20"> </td>
<td><input type="text" name="name18" id="name3" size="15"> <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /></td>
<td><input type="text" name="name19" id="name4" size="15"><img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12')" /> </td>
</tr>
<tr>
<td> <label>5 </label> </td>
<td><input type="text" name="name20" id="name" size="20"> </td>
<td><input type="text" name="name21" id="name" size="20"> </td>
<td><input type="text" name="name22" id="name" size="20"> </td>
<td><input type="text" name="name23" id="name3" size="15"> <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /></td>
<td><input type="text" name="name24" id="name4" size="15"><img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12')" /> </td>
</tr>
</table>