1

How can I retrieve values of multiple input boxes that can be added dynamically,using 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'>&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>

This is the part that we can have any number of input fields as necessary from the above 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>

How can I get the dynamic input boxes and then add it to a DB using servlets?

TheShadow123
  • 185
  • 2
  • 14
  • @rmertins: good, so they do not use Servlet or JSP? Everything is built on top of those!! – PeakGen Feb 11 '15 at 09:53
  • Servlets still exist, but coupling webguis based in MVC based JSF with simple CDI enhanced Beans is much easer. You dont have to handle requests etc. You get ajax support out of the box and much mor. Here is a good overview: http://jaxenter.com/introducing-the-java-ee-web-profile-103275.html – Rene M. Feb 11 '15 at 10:03

1 Answers1

2

The ID's of your input elements have to be unique and to list all parameters you can use request.getParameterMap() and iterate through it from a servlet.

See Get all parameters from JSP page for more examples

Community
  • 1
  • 1