本系列博客汇总在这里:Struts2 汇总

Struts2 对 EL表达式的支持


源码工程文件为:struts2_18

EL 表达式

${name}:调用 pageContext.findAttribute(“name”),从页面、请求、会话、应用范围去查找 key=name 对应的值。

<h3>使用el表达式来输出table</h3>
<table border="1">
	<tr>
		<th>id</th>
		<th>姓名</th>
		<th>性别</th>
		<th>索引</th>
		<th>序号</th>
		<th>是否首行</th>
		<th>是否尾行</th>
		<th>奇数</th>
		<th>偶数</th>
	</tr>
	<s:iterator value="personList" var="p" status="status">
	<tr bgcolor="${status.odd?'#c3f3c3':'#f3c3f3'}">
		<td>${p.personId}</td>
		<td>${p.personName}</td>
		<td>${p.gender == 1?'男':'女' }</td>
		<td>${status.index}</td>
		<td>${status.count}</td>
		<td>${status.first}</td>
		<td>${status.last}</td>
		<td>${status.odd}</td>
		<td>${status.even}</td>
	</tr>
	</s:iterator>
</table>

Struts2(17)_Struts2 对 EL表达式的支持_el表达式
Struts 中 EL表达式 ${name} 查找范围依次按着如下顺序查找:请求 > 值栈 > contextMap > 会话 > 应用。

如有错误,欢迎指正!