Spring 3 - accessing model values โ€‹โ€‹in JSP

I have a JSP where I am trying to print values โ€‹โ€‹from my model, but nothing appears in the place where I refer to these values. Here is the controller method where I set the values.

@RequestMapping(value = "/poll1", method = RequestMethod.POST) public String processPoll1(@RequestParam String vote, HttpServletResponse response, Model model) { Map<String, Object> resultMap = poll1DAO.tallyVote(vote); Cookie poll1 = new Cookie("poll1", "voted"); model.addAttribute("poll1Yes", resultMap.get("yes").toString()); model.addAttribute("poll1No", resultMap.get("no").toString()); poll1.setMaxAge(maxSeconds); response.addCookie(poll1); return "redirect:/polls"; } 

Here is the part of the JSP where I relate to Model attributes.

 <table> <tr> <td><b><i>Poll #1 -- </i></b>Would you like to have a 30-year reunion in 2016?<br></td> </tr> <tr> <td><b>Yes</b></td> <td>&nbsp;&ndash;&nbsp;<c:out value='${model.poll1Yes}' /><br /></td> </tr> <tr> <td><b>No</b></td> <td>&nbsp;&ndash;&nbsp;<c:out value='${model.poll1No}' /><br /> </td> </tr> </table> 

Here is my conclusion. Instead of the actual values โ€‹โ€‹in the attribute locations, nothing is printed.

 Poll #1 -- Would you like to have a 30-year reunion in 2016? Yes โ€“ No โ€“ 
+7
source share
1 answer

No need to reference model in your JSP.

 <c:out value='${poll1Yes}' /> <c:out value='${poll1No}' /> 
+5
source

All Articles