如何使用JSP,Servlets检索可以动态添加的多个输入框的值?
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Name:</label>
<div class="col-md-8">
<input id="textinput" name="textName" type="text" placeholder="" class="form-control input-md" >
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Address Line 1:</label>
<div class="col-md-8">
<input id="textinput" name="textadr1" type="text" placeholder="" class="form-control input-md" >
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Address Line 2:</label>
<div class="col-md-8">
<input id="textinput" name="textadr2" type="text" placeholder="" class="form-control input-md" >
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Country:</label>
<div class="col-md-4">
<input id="textinput" name="textcntry" type="text" placeholder="" class="form-control input-md" >
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Registration Number:</label>
<div class="col-md-4">
<input id="textinput" name="textregNo" type="text" placeholder="" class="form-control input-md" >
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Registration Date:</label>
<div class="col-md-4">
<input id="textinput" name="textregDate" type="date" class="form-control input-md" >
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Date of Dealing:</label>
<div class="col-md-4">
<input id="textinput" name="textDateDealing" type="date" class="form-control input-md" >
</div>
</div>
</fieldset>
<div id="contact-person-container">
<div class="contact-person">
<hr>
<fieldset id="modal_form">
<button type='button' class='close closebtn' aria-hidden='true'>×</button>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Contact Person:</label>
<div class="col-md-4">
<input id="textinput" name="textinput" type="text" placeholder="" class="form-control input-md" >
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Phone #:</label>
<div class="col-md-4">
<input id="textinput" name="textinput" type="text" placeholder="(_ _ _) _ _ _ _ _ _ _" class="form-control input-md" >
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">fax #:</label>
<div class="col-md-4">
<input id="textinput" name="textinput" type="text" placeholder="(_ _ _) _ _ _ _ _ _ _" class="form-control input-md" >
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Email:</label>
<div class="col-md-8">
<input id="textinput" name="textinput" type="email" placeholder="" class="form-control input-md" >
</div>
</div>
</fieldset>
</div>
</div>
<!-- /#contact-person-container -->
</div>
<div class="modal-footer">
<button type="button" id="addAnotherContactBtn" class="btn btn-
primary">Add Another Contact</button>
<button type="submit" class="btn btn-primary">Create Agent</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</form>
这是我们可以根据需要从上面的表格中获得任意数量的输入字段的部分。
<fieldset id="modal_form">
<button type='button' class='close closebtn' aria-hidden='true'>×</button>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Contact Person:</label>
<div class="col-md-4">
<input id="textinput" name="textinput" type="text" placeholder="" class="form-control input-md" >
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Phone #:</label>
<div class="col-md-4">
<input id="textinput" name="textinput" type="text" placeholder="(_ _ _) _ _ _ _ _ _ _" class="form-control input-md" >
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">fax #:</label>
<div class="col-md-4">
<input id="textinput" name="textinput" type="text" placeholder="(_ _ _) _ _ _ _ _ _ _" class="form-control input-md" >
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Email:</label>
<div class="col-md-8">
<input id="textinput" name="textinput" type="email" placeholder="" class="form-control input-md" >
</div>
</div>
如何获取动态输入框,然后使用servlet将其添加到数据库?
答案 0 :(得分:2)
输入元素的ID必须为unique
并列出您可以使用request.getParameterMap()
的所有参数,并从servlet中迭代它。
有关更多示例,请参阅Get all parameters from JSP page