JSTL的使用
eclipse需要导入JSTL包,myeclipse/Idea 自带生成
jstl-impl.jar
javax.servlet.jsp.jstl.jar
JSTL Jsp Standard Tag Lib
c:核心库
fn:函数库
fmt:格式化库
导入:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core " %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
JSTL的循环
<c:forEach items="${requestScope.questionTypes}" var="questionType">
<tr>
<td>${questionType.id}</td>
<td>${questionType.title}</td>
</tr>
</c:forEach>
JSTL的if条件
<c:if test="${i eq requestScope.pager.pageNum}" var="isCur">
<span class="current">${i}</span>
</c:if>
<c:if test="${not isCur}">
<a href="#">${i}</a>
</c:if>
与作用范围有关的EL隐含对象包含有:pageScope、requestScope、sessionScope和applicationScope
它们可以读取使用JSP内置对象pageContext、request、session以及application的setAttribute()方法所设定的对象的数值-----即getAttribute(String name),却不能取得其他相关信息。
Page:PageScope,使用方式${ pageScope.page_name }
Request:RequestScope,使用方式${ requestScope.request_name },相当于<%=request.getAttribute("request_name");%>
Session:SessionScope,使用方式${ sessionScope.session_name },相当于<%=session.getAttribute("session_name");%>
Application:ApplicationScope,使用方式${ applicationScope.application_name },相当于<%=application.getAttribute("application_name");%>
EL表达式中定义了11个隐式对象,使用这些隐式对象可以很方便地读取到Cookie、HTTP请求消息头字段、请求参数、
Web应用程序中的初始化参数的信息,EL表达式中的隐式对象具体如下: