Jstl标签(一)

来源:互联网 发布:淘宝店铺宣传团队抽成 编辑:程序博客网 时间:2024/06/06 04:47
<%@page import="com.test.Customer"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
   <h4>c:choose,c:when,c:otherwise:可以实现if...else if...else的效果</h4>
   <c:choose>
    <c:when test="${param.age>18}">青年</c:when>
    <c:when test="${param.age>35}">中年</c:when>
    <c:when test="${param.age>60}">老年</c:when>
    <c:otherwise>未成年</c:otherwise>
   </c:choose>
<h4>c:if</h4>
<c:set value="20" var="age" scope="request"></c:set>
<c:if test="${requestScope.age>18}">成年了</c:if><br/>
<c:if test="${param.age>18}" var="isAdult" scope="request">成年了!</c:if><br/>
     isAdult:<c:out value="${requestScope.isAdult}"></c:out><br/>
     <h4>c:remove</h4>
     <c:set value="1997-09-01" var="date" scope="session"></c:set>
     date:${sessionScope.date }<br/><br/>
     <c:remove var="date" scope="session"/>
      date:${sessionScope.date }<br/><br/>
<h4>c:set: 可以为域赋属性值, 其中 value 属性支持 EL 表达式; 还可以为域对象中的 JavaBean 的属性赋值, target, value都支持 EL 表达式</h4>
<c:set var="name" value="ATGUIGU" scope="page"></c:set>
<%-- 
pageContext.setAttribute("name", "atguigu");
--%>
name: ${pageScope.name }
<br><br>
<c:set var="subject" value="${param.subject }" scope="session"></c:set>
subject: ${sessionScope.subject }
<br><br>
<% 
Customer cust = new Customer();
cust.setId(1001);
request.setAttribute("cust", cust);
%>
ID: ${requestScope.cust.id }
<c:set target="${requestScope.cust }" property="id" value="${param.id }"></c:set>
<br>
ID: ${requestScope.cust.id }
<br><br>
<h4>c:out: 可以对特殊字符进行转换. </h4>
<% 
request.setAttribute("book", "<<Java>>");
%>
book: ${requestScope.book }
<br><br>
book: <c:out value="${requestScope.book }" default="booktitle"></c:out>
</body>
</html>
0 0