Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3965322
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:26:52+00:00 2026-05-20T03:26:52+00:00

[spring 3.0.5] MVC I have on class like that: public class Address { private

  • 0

[spring 3.0.5] MVC

I have on class like that:

public class Address {

  private String street;
  private String city;

  public String getStreet() {
     return this.street;
  }

  public void setStreet(String street) {
     this.street = street;
  }

  public String getCity() {
     return this.city;
  }

  public void setCity(String city) {
    this.city = city;
  }
}

My function is to rely on the possibility of adding an infinite number of addresses on the site (JSP with spring and form tag). Can somebody give a skeleton of such functionality in the controller?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T03:26:52+00:00Added an answer on May 20, 2026 at 3:26 am

    Your question is a little unclear. The answer is twofold:

    Displaying a list of addresses

     @Controller
     public class SomeController {
    
         @RequestMapping("/somepage.jsp ") 
         public String somePage(HttpServletRequest request, ModelMap model) {
             List<Address> addresses = ....
             // We can now access the key "addresses" in our jsp
             model.put("addresses", addresses);
             return "/WEB-INF/jsp/somepage.jsp";
         }
     }
    

    In your jsp page, you can display the list of addresses using e.g., the core jstl lib, here noted using the prefix c.

    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <html> 
       ...
    
        <c:forEach items="${addresses}" var="addr">
            City:   ${addr.city}   <br/>
            Street: ${addr.street}
        </c:forEach>
    
       ....
    </html>
    

    Submitting addresses

    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 creates two additional form fields. Ensure each form field will get a unique name, e.g., :

     <input type="text" name="street_1" />
     <input type="text" name="city_1" />
    
     <input type="text" name="street_2" />
     <input type="text" name="city_2" />
    
     ....
    

    Then you can iterate the fields using request.getParameterMap(), where you construct your address options based on matching names (e.g., street_1 should be associated with city_1 and so forth).

    [EDIT] 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 might look like).

    var i = 0; // initialize to how many addresses you initially display
    function addAddress() {
        var form = document.getElementById('form');
        var html = '<input type="text" name="street_' + i + '" />' + 
                   '<input type="text" name="city_'   + i + '" />';
        form.innerHTML += html;
        i++;
    }
    

    Then call the javascript when pressing a button:

    <input type="button" onClick="addAddress();" value="add address" />
    

    If you decided to use e.g., jQuery this would be even easier. E.g.,

    var i  = 0:
    $("#addbtn").click(function() {
        $("#someId").append(
             '<input type="text" name="street_' + i + '" />' + 
             '<input type="text" name="city_'   + i + '" />');
        i++;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine that I have a Spring MVC controller something like this: @Controller @RequestMapping(/base-url) public
I have a class structure that looks like this: class Person { public virtual
I use Spring MVC 3.0 and JSP. I have an object: public class ObjectWrapper
Say you have the following object: public class Address { public String Line1 {
I have a command object: public class Job { private String jobType; private String
I am using spring 3 mvc/security frameworks. I have created a Controller class that
I have a Spring MVC Controller class (bean): @Controller @RequestMapping(/index.jsp) public class EjbCaller {
I have a Spring MVC Controller class that needs a property set from a
I have a model class like following public class ProductModel { string ProductName {
I have a form in spring mvc 2 having command class Class1 I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.