1. session 里放的数据可以在其他页面使用,比如用户信息,
后端放入session:
request.getSession().setAttribute("manage", manage);
session生命周期内,前端的很多页面都可以使用 <c:if test="${sessionScope.manage !=null}"> <p>热泪欢迎${sessionScope.manage.getUsername()}</p> </c:if>
2. model的数据,只能在接下来的页面使用,其他页面就不能使用,比如从数据库获得的list<对象>信息,在下一个页面,循环遍历展示
后端放入model model.addAttribute("item_categoryList", item_categoryList);
前端
<c:forEach items="${item_categoryList}" var = "item_category"> <tr> <td>${item_category.id}</td> <td>${item_category.name}</td> </tr> </c:forEach>
3. 存入session后,取出数据使用get()方法,像是对象,而model使用点,有点类似json字符串