May 2015
Intermediate to advanced
234 pages
4h 18m
English
In this recipe, you'll learn how to set attributes in a controller method and use them in a JSP view.
Here are the steps to pass data from a controller to a view:
Model argument to the controller method: @RequestMapping("/user/list")
public void userList(Model model) {
...Model object:model.addAttribute("nbUsers", 13);<p>There are ${nbUsers} users</p>The nbUsers variable is set to 13 in the controller. In the JSP file, the ${nbUsers} EL (Expression Language) element will be rendered to 13, so that the following HTML will be returned:
<p>There are 13 users</p>
Read now
Unlock full access