JSP 在使用forEach
标签时报错:According to TLD or attribute directive in tag file, attribute items does not accept any expressions。
原因:web.xml
的web-app_2_5.xsd
版本大于2.3
,需要使用jstl
的扩展标签。
解决:jsp
文件引用的jstl core
标签库改为扩展标签库,
将:<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
替换成:<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
。
差异:2.5版本可以根据索引 ID 取出 List 里的单个值, 2.3版本就不行。
1 2 3 4 5 6 7
| <body> <!-- 从list集合中根据索引位取值 --> <h3>${list[0] }</h3> <h3>${list[1] }</h3> <h3>${list[2] }</h3> <h3>${list[3] }</h3> </body>
|