session中是键值对:
EL
session.setAttribute("age","123");
${ sessionScope.age} 在页面上显示的就是123了
sessionScope指的是session的范围,类似还有requestScope,pageScope,contextScope
然后后面的age表示的是set属性时的key值
<% %>
session是jsp的内置对象,所以你可以直接写在jsp的
<%
session.setAttribute("a", b); //把b放到session里,命名为a,
String M = session.getAttribute(“a”).toString(); //从session里把a拿出来,并赋值给M
%>
<%=request.getSession().getAttribute("age") %>
session中是对象:
${sessionScope.teacher.teachername}
先在page中import="java.util.*,cn.zt.entity.Teacher"
<% Teacher teacher=(Teacher)request.getSession().getAttribute("teacher");
out.print(teacher.getTeachername());%>
session中是对象数组:
jstl方法:
jsp中头部添加
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<table>
<c:forEach items="${list}" var="bean">
<tr>
<td>${bean.id}</td>
<td>${bean.name}</td>
</tr>
</c:forEach>
</table>
原文链接:https://blog.csdn.net/tao911110/article/details/79688058