Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your question is a little unclear. The answer is twofold: </p> <h1>Displaying a list of addresses</h1> <pre><code> @Controller public class SomeController { @RequestMapping("/somepage.jsp ") public String somePage(HttpServletRequest request, ModelMap model) { List&lt;Address&gt; addresses = .... // We can now access the key "addresses" in our jsp model.put("addresses", addresses); return "/WEB-INF/jsp/somepage.jsp"; } } </code></pre> <p>In your jsp page, you can display the list of addresses using e.g., the <code>core</code> jstl lib, here noted using the prefix <code>c</code>. </p> <pre><code>&lt;%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt; &lt;html&gt; ... &lt;c:forEach items="${addresses}" var="addr"&gt; City: ${addr.city} &lt;br/&gt; Street: ${addr.street} &lt;/c:forEach&gt; .... &lt;/html&gt; </code></pre> <h1>Submitting addresses</h1> <p>If you're looking to submit an undefined number of addresses, that's a little more tricky. What you could do is create a javasript form template which upon a button press or so <a href="http://www.dustindiaz.com/add-and-remove-html-elements-dynamically-with-javascript/" rel="nofollow">creates</a> two additional form fields. Ensure each form field will get a unique name, e.g., : </p> <pre><code> &lt;input type="text" name="street_1" /&gt; &lt;input type="text" name="city_1" /&gt; &lt;input type="text" name="street_2" /&gt; &lt;input type="text" name="city_2" /&gt; .... </code></pre> <p>Then you can iterate the fields using <code>request.getParameterMap()</code>, where you construct your address options based on matching names (e.g., street_1 should be associated with city_1 and so forth). </p> <p><strong>[EDIT]</strong> To give you an idea of what the javascript could look like, I give you this from the top of my head (note I haven't tested this code, it's there to give you an idea of what it <em>might</em> look like). </p> <pre><code>var i = 0; // initialize to how many addresses you initially display function addAddress() { var form = document.getElementById('form'); var html = '&lt;input type="text" name="street_' + i + '" /&gt;' + '&lt;input type="text" name="city_' + i + '" /&gt;'; form.innerHTML += html; i++; } </code></pre> <p>Then call the javascript when pressing a button: </p> <pre><code>&lt;input type="button" onClick="addAddress();" value="add address" /&gt; </code></pre> <p>If you decided to use e.g., <a href="http://jquery.com/" rel="nofollow">jQuery</a> this would be even easier. E.g., </p> <pre><code>var i = 0: $("#addbtn").click(function() { $("#someId").append( '&lt;input type="text" name="street_' + i + '" /&gt;' + '&lt;input type="text" name="city_' + i + '" /&gt;'); i++; }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload