Results 1 to 4 of 4

Thread: Attributes in application scope into JSP

  1. #1
    Join Date
    Oct 2011
    Posts
    1

    Default Attributes in application scope into JSP

    Hi.
    What is the best practise in Spring 3 MVC to solve the following issue (using annotations) ? :

    When I start applicatiion I need to load into application scope some dictionary values (i.e. list of countries).
    Then when user enters jsp page I need to load into combobox component values from this application scope.
    I need also to be able to access to that list and change some values.
    Could you provide me with some code snippets?

    Thanks for reply.

  2. #2
    Join Date
    Dec 2010
    Posts
    315

    Default

    Take a look at @ModelAttribute which you can use to prepopulate a list of objects to be displayed on the JSP.

    Another solution is to use AJAX, preferrably via jQuery. From jQuery, perform a get AJAX (or post if you prefer) and once the data arrives, prepopulate your combo box.

  3. #3

    Default

    A servlet is a Java programming language class used to extend the capabilities of servers that host applications accessed via a request-response programming model. Although servlets can respond to any type of request, they are commonly used to extend the applications hosted by Web servers. Thus, it can be thought of as a Java Applet that runs on a server instead of a browser.

  4. #4
    Join Date
    Sep 2011
    Posts
    17

    Default

    Add the list of countries to the model and view object:

    Code:
    // constructs list of countries
    List<Country> countryList = new ArrayList<Country>();
    // populate countries...
    
    // add to model
    mav.add("listCountry", countryList);
    Then in your JSP page, use <iterate> tag to iterates over the country list and display the information you need.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •