<%request.getSession().setAttribute("sampleValue", new Integer(10));%>
${sessionScope.sampleValue}
取得保存在 Session 中参数的 sessionScope 变量的 EL 表达式,“ . ”是 property 访问操作符,在这里表示从 Session 中取得“键”为“sampleValue ”的参数,并显示出来。显示结果为“ 10 ”。
<%@ page contentType="text/html; charset=UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<form action="SampleJsp.jsp">
<input type="text" name="sampleValue" value="10">
<input type="text" name="sampleValue" value="11">
<input type="text" name="sampleValue" value="12">
<input type="text" name="sampleSingleValue" value="SingleValue">
<input type="submit" value="Submit">
</form>
</body>
</html>
在这个页面中定义了两组控件,控件名为“ sampleValue ”的是一套控件数组,控件名为“ sampleSingleValue ”的是单一控件,通过递交将请求参数传送到 SampleJsp.jsp 。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
${paramValues.sampleValue[2]} <br>
${param.sampleSingleValue} <br>
</body>
</html>
这是请求转发到的页面,通过 EL 表达式的 paramValues 变量得到控件数组中最后一个控件的递交参数,通过 EL 表达式的 param 变量得到单一控件的递交参数。