In Spring, I have a contact.jsp page with such a variable check, from where it takes this contactList variable, there is such code in the controller.

@RequestMapping("/contact") public String listContacts(Map<String, Object> map) { map.put("contact", new Contact()); map.put("contactList", contactService.listContact()); return "contact"; } 

who passes it as a map parameter and how does it return it to jsp?

    1 answer 1

    map (model) comes as a parameter when processing the request. Spring allows different options for function parameters to use. Returning also allows different options, in this case returns the name View. And the model according to the ideas comes by reference, is filled in and can be used further in the View. You can read more here, if English is good - http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html/mvc.html

    • And by what names you can get these names, in this case the name of the variable "map" - J Mas
    • one
      The model in the handler must be a Model ( docs.spring.io/spring/docs/current/javadoc-api/org/… ). The model has an addAttribute method that allows you to add values ​​by name. Or you can return ModelAndView. And later on in the view rendering, the data is available by the names that were used for the attachment. - Anton M.
    • understandably. Thank you - J Mas
    • and here that $ {sessionScope ["SPRING_SECURITY_LAST_EXCEPTION"] is returned.] message} what is this model and what should be written in square brackets - J Mas