java - 如何使用 JSP、Servlet 检索可动态添加的多个输入框的值?

标签 java html jsp servlets

如何使用 JSP、Servlet 检索可动态添加的多个输入框的值?

        <!-- 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'>&times;</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'>&times;</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 将其添加到数据库?

最佳答案

输入元素的 ID 必须是 unique 要列出所有参数,您可以使用 request.getParameterMap() 并从 servlet 迭代它。

参见Get all parameters from JSP page更多示例

关于java - 如何使用 JSP、Servlet 检索可动态添加的多个输入框的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28450444/

相关文章:

java - 使用 MySQL 转义 REGEXP 中的字符串文字

java - Android:用 `MPAndroidChart`绘制水平条形图

javascript - 如何从struts html属性获取文档Id

html - 无法居中 div 尝试 float 到左侧文本对齐边距 :auto just wont work

javascript - 如何获取特定的视频时间,然后用它来触发事件

java - spring 模型对象未在 jsp 页面上呈现

java - 如何删除 Spring Boot 应用程序中的白色标签错误页面?

java - 如何创建一个 ASM LdcInsnNode 将当前类静态添加到堆栈中?

java - 使用 Serialized 保存信息

javascript - 如何在没有 Web 服务器的情况下运行 ajax 代码?