Jstl标簽庫
自定義标簽庫
Mvc設計模式
Java三層架構
Jstl概述
Apache提供的,必須要導入jar包
Core 核心标簽庫,c标簽
<c:out>輸出
1value:可以是字元串常量,也可以是el表達式
2default:當要輸出的内容為null時,會輸出default指定的值。
3escapeXml:預設為true ,表示轉義。
<c:set>
1var:變量名
2value:變量值可以為el表達式
3scope:預設為page,可選值page,request,Session,application
Remove删除域變量
Var變量名
Scope如果不給出scope,表示删除所有域中的該名稱的變量,如果指定了域,那麼隻删除該域的變量。
url
value指定一個路徑!給他會在路徑前面自動添加項目名
可以給url後面添加參數
<c:param>name value
Var 指定變量名,,一旦加入這個屬性,那麼url标簽就不會在輸出到頁面,而是把生成url儲存到域中
Scope它與var一起使用,用來儲存url。
If語句
<c:if test="布爾類型">…</c:if>:當test為真時執行标簽體内容
Choose語句
<c:choose>
<c:when test="">…</c:when>
<c:otherwise></c:otherwise>
</c:choose>
Foreach
<c:forEach var="i" begin="i" end="10" syep="2">${i}
</c:forEach>
Items要便利的是集合
Var把數組或集合中的每個元素複制給var指定的變量。
循環狀态varstatus 來建立循環狀态變量。
Count
Index
First
Last
Current目前元素
代碼
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP '2.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> http-equiv="cache-control" http-equiv="expires" content="0"> http-equiv="keywords" content="keyword1,keyword2,keyword3"> http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> This is my JSP page. <br> <c:set var="code" value="<script>alert('hello');</script>" scope="request"/> <c:out value="${code }" escapeXml="true"/><br> <c:url value="/Aservlet"/><br> ${pageContext.request.contextPath }/Aservlet <a href="<c:url value='/index.jsp'">點選此處回到首頁</a> <br> <c:url value='/indfex.jsp'> <c:param name="name" value="張三"></c:param> </c:url> <hr> <c:if test="${empty param.name }"> 您沒有給出名為name的參數! </c:if> <c:choose> <c:when test="${empty param.name }">您沒有給出名為name的參數</c:when> <c:otherwise>誰讓你給出name參數的!${param.name }</c:otherwise> </c:choose> <c:forEach var="i" begin="1" end="10" step="2"> ${i }<br> </c:forEach> <%String []strs={"one","two"}; request.setAttribute("strs", strs); %> items="${strs }" var="str"> ${str }<br> <% ArrayList<String> list=new ArrayList<String>(); list.add("一"); list.add("二"); list.add("三"); pageContext.setAttribute("list", list); items="${1list }" var="ele" varStatus="vs"> ${vs.index }${vs.count }${vs.first }${vs.last }${vs.current }<br> </body> </html> |
Fmt标簽庫
格式化
<fmt:formatData value="${d}" partten="yyyy-MM-dd HH:mm:ss"/>
<fmt:formatNumber value="${number}" partten=""/>
0.00保留小數點位數,四舍五入
不足補零
#.##不補位數
自定義标簽
Mvc設計模式
他不是Java獨有的,所有的b/s結構的項目都在使用它
M model模型(自己寫代碼)
V view 視圖(jsp)
C control控制器(servlet)
不隻是一個。