First, SpringMVC the Controller to transfer data about jsp There are five ways:
1. Model:
Model model;
model.addAttribute("xxx", xxx);
Return String, that is the view name.
2. Use HashMap:
HashMap<String,Object> hashMap;
hashMap.put("xxx", xxx);
Return String, that is the view name.
3. Use Session:
HttpSession session;
session.setAttribute("xxx", xxx);
Return String, that is the view name.
4. Use Request:
HttpServletRequest request;
request.setAttribute("xxx", xxx);
Return String, that is the view name.
5. ModelAndView:
ModelAndView modelAndView;
view.addObject("xxx", xxx);
view.setViewName ( "xxx"); // here to view names
Return type ModelAndView.
However, no matter which method I use, you can not take the value of the code and run shots are as follows:
Controller:
@RequestMapping(value = "/selectCityByLevel")
public String SelectCityByLevel(Model model){
List<City> cities = new ArrayList<City>();
cities = cityService.FindCityByLevel(1);
model.addAttribute("cities",cities);
return "test";
}
JSP(test.jsp):
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>Title</title>
</head>
<body>
<c:forEach items="${cities}" var="list">
${list.name}
</c:forEach>
</body>
</html>
Run shot:
Internet Baidu, the investigation did not day to find the problem, it crashes!
Finally heaven pays off! ! ! I finally pulled out! ! ! !
This is after the turn over the code, see it yet? ! !
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>Title</title>
</head>
<body>
<c:forEach items="${cities}" var="list">
${list.name}
</c:forEach>
</body>
</html>
It is to pay more of this stuff! ! !
Run shot:
So I did the next Internet Baidu reason, they borrow the words of the great God, it is this:
"IsELIgnored property in the page directive is used to specify whether to ignore the format: <% @ page isELIgnored =." True | false "%>.
If set to true, then the JSP expression is treated as a string! ! ! "