屬性名 | 是否支持EL | 屬性類型 | 屬性描寫敘述 |
value | true | Object | 指定要輸出的內容 |
escapeXml | true | Boolean | 指定是否將>、<、&、'、" 等 特殊字符進行HTML編碼轉換 後再進行輸出。默認值是true。 |
default | true | Object | 指定假設value屬性的值爲null時所輸出的默認值 |
<!-- c:out 輸出數據到瀏覽器 --> <c:out value="Hello c out "></c:out> Hello c out <!-- 輸出一個變量 --> <c:set var="m" value="10" scope="page"/> <c:out value="${m}"></c:out> ${m } <!-- 轉義HTML 默認轉義,經過設置escapeXml 爲false 不進行轉義--> <c:out value="<a href='xxx'>link</a>" /> ${fn:escapeXml("<a href='xxx'>link</a>") } <!-- 贊成輸出默認值 ,假設city不存在,輸出北京--> <c:out value="${city}" default="北京"></c:out> ${empty city?"北京":city }
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!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>傳統方式</h4> <%= "Hello" %> <% int a = 10; request.setAttribute("name", "xy"); %> <%= a %> <h4>JSTL的方式 </h4> <c:out value="Hello"></c:out> <c:out value="${name }"></c:out> <!-- "" --> <c:out value="${ city }" default="北京"></c:out> <c:out value="<a href='#'>超連接</a>" escapeXml="false"/> <c:out value="<a href='#'>超連接2</a>" escapeXml="true"/> </body> </html>
屬性名 | 是否支持EL | 屬性類型 | 屬性描寫敘述 |
value | true | Object | 用於指定屬性 |
var | false | String | 用於指定要設置的Web域屬性的名稱 |
scope | false | String | 用於指定屬性所在的Web域 |
target | true | Object | 用於指定要設置屬性的對象。這個對象必須是 JavaBean對象或java.util.Map對象 |
property | true | String | 用於指定當前要爲對象設置的屬性名稱 |
<%@page import="cn.itcast.vo.User"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!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>傳統方式</h4> <% pageContext.setAttribute("name", "10", pageContext.REQUEST_SCOPE); %> <% User user = new User(); user.setUsername("美美"); user.setPassword("123"); request.setAttribute("user", user); %> ${ user.username } <h4>JSTL方式</h4> <c:set var="i" value="10" scope="request" ></c:set> ${ i } <c:set target="${ user }" property="username" value="小鳳"></c:set> ${ user.username } </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!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>傳統方式</h4> <% request.setAttribute("name", "美美"); request.removeAttribute("name"); %> <c:set var="name" value="小鳳" scope="page"></c:set> ${ name } <c:remove var="name" scope="page"/> ${name } </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!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>傳統方式</h4> <% try{ }catch(Exception e){ e.printStackTrace(); } %> <h4>JSTL的方式</h4> <c:catch var="e"> <% int a = 10/0; %> </c:catch> ${ e.message } </body> </html>
屬性名 | 是否支持EL | 屬性類型 | 屬性描寫敘述 |
test | true | boolean | 決定是否處理標籤體中的內容的條件表達式 |
var | false | String | 用於指定將test屬性的運行結果保存到某個Web域中的某個屬性的名稱 |
scope | false | String | 指定將test屬性的運行結果保存到哪一個Web域中 |
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!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>傳統方式</h4> <% int a = 10; if(a >= 10){ out.print("a >= 10"); }else{ out.print("a < 10"); } %> <h4>JSTL方式</h4> <c:set var="i" value="10" scope="page"></c:set> <c:if test="${ i ge 10 }" var="x" scope="page"> i >= 10 </c:if> <c:if test="${ i lt 10 }"> i < 10 </c:if> ${ x } </body> </html>
使用<c:choose>,<c:when>,<c:otherwise>三個標籤,可以構造相似於"if-else if-else"的複雜條件推斷結構html
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!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>獲取參數</h4> <%= request.getParameter("username") %> <h4>傳統方式</h4> <% int a = 10; if(a >= 10 ){ out.print("a >= 10"); }else if(a < 10){ out.print("a < 10"); }else{ out.print("其它"); } %> <h4>JSTL方式</h4> <c:set var="i" value="10" scope="page"></c:set> <c:choose> <c:when test="${ i ge 10 }"> i >= 10 </c:when> <c:when test="${ i lt 10 }"> i < 10 </c:when> <c:otherwise> 其它 </c:otherwise> </c:choose> </body> </html>
屬性名 | 是否支持EL | 屬性類型 | 屬性描寫敘述 |
var | false | String | 指定將當前迭代到的元素保存到page這個域中的屬性名稱 |
varStatus | false | String | 記住用於保存迭代信息的對象 |
items | true | 不論什麼支持的類型 | 將要迭代的集合對象 |
begin | true | int | 假設指定items屬性,就從集合中的第begin個元素開始進行迭代 。begin的索引值從0開始編號。假設沒有指定items屬性,就從 begin指定的值開始迭代。直到end值時結束迭代 |
end | true | int | 與begin屬性相似 |
step | true | int | 指定迭代的步長,即迭代因子的迭代增量 |
<c:forEach>迭代數據java
屬性 | 類型 | 意義 |
index | number | 現在指到成員的索引 |
count | number | 總共指到成員的總數 |
first | boolean | 現在指到的成員是不是第一個成員 |
last | boolean | 現在指到的成員是不是最後一個成員 |
<%@page import="cn.itcast.vo.User"%> <%@page import="java.util.HashMap"%> <%@page import="java.util.Map"%> <%@page import="java.util.ArrayList"%> <%@page import="java.util.List"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!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>遍歷數組</h4> <% String [] arrs = {"美美","小鳳","芙蓉","小蒼"}; request.setAttribute("arrs", arrs); %> <!-- for(String s : arrs){ } --> <c:forEach var="s" items="${ arrs }"> ${ s } </c:forEach> <h4>遍歷集合</h4> <% List<String> list = new ArrayList<String>(); list.add("美美"); list.add("小鳳"); list.add("芙蓉"); list.add("小澤"); request.setAttribute("list", list); %> <c:forEach var="s" items="${ list }"> ${ s } </c:forEach> <h4>遍歷Map集合</h4> <% Map<String,String> map = new HashMap<String,String>(); map.put("aa", "美美"); map.put("bb", "小鳳"); map.put("cc", "芙蓉"); request.setAttribute("map", map); %> <c:forEach var="entry" items="${ map }"> ${ entry.key } -- ${ entry.value } </c:forEach> <h4>遍歷對象的集合</h4> <% List<User> uList = new ArrayList<User>(); uList.add(new User("美美","123")); uList.add(new User("小風","234")); uList.add(new User("芙蓉","345")); request.setAttribute("uList", uList); %> <c:forEach var="user" items="${ uList }"> ${ user.username } -- ${ user.password } </c:forEach> <h4>迭代數據</h4> <h4>迭代從1到10</h4> <c:forEach var="i" begin="1" end="10" step="2"> ${ i } </c:forEach> <h4>計算從1加到100的和</h4> <c:set var="sum" value="0" scope="page"></c:set> <c:forEach var="i" begin="1" end="100" step="1" varStatus="status"> <c:set var="sum" value="${ sum + i }"></c:set> </c:forEach> ${ sum } <h4>遍歷10到100的偶數,每到第3個數,顯示紅色</h4> <c:forEach var="i" begin="10" end="100" step="2" varStatus="status"> <c:choose> <c:when test="${ status.first }"> <font color="blue">${ i }</font> </c:when> <c:when test="${ status.count % 3 eq 0 }"> <font color="red">${ i }</font> </c:when> <c:otherwise> ${ i } </c:otherwise> </c:choose> </c:forEach> </body> </html>
名稱 | 說明 | EL | 類型 | 必須 | 默認值 |
var | 用來存放現在指到的成員 | N | String | 否 | 無 |
items | 被迭代的字符串 | Y | String | 是 | 無 |
delims | 定義用來切割字符串的字符 | N | String | 是 | 無 |
varStatus | 用來存放現在指到的相關成員信息 | N | String | 否 | 無 |
begin | 開始的位置 | Y | int | 否 | 0 |
end | 結束的位置 | Y | int | 否 | 最後一個成員 |
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!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>分隔字符串</h4> <c:set var="i" value="aa,bb,cc" scope="page"></c:set> <c:forTokens items="${i }" delims="," var="x"> ${ x } </c:forTokens> </body> </html>
名稱 | 說明 | EL | 類型 | 必須 | 默認值 |
url | 一文件被包括的地址 | Y | String | 是 | 無 |
context | 項目虛擬路徑 | Y | String | 否 | 無 |
var | 儲存被包括的文件的內容(以String類型存入) | Y | String | 否 | 無 |
scope | var變量的JSP範圍 | N | String | 否 | page |
charEncoding | 被包括文件的內容的編碼方式 | Y | String | 否 | 無 |
varReader | 儲存被包括的文件的內容(以Reader類型存入) | N | String | 否 | 無 |
<!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>JSTL方式</h4> <c:import url="/jstl/choose.jsp" context="/day13" var="i" scope="page"> <c:param name="username" value="meimei"></c:param> </c:import> ${ i } </body> </html>
(相似於Session追蹤 尤爲是當瀏覽器禁用cookie後,就是說實現了session追蹤的功能)web
屬性名 | 是否支持EL | 屬性類型 | 屬性描寫敘述 |
value | true | String | 指定要構造的URL |
var | false | String | 指定將構造出的URL結果保存到Web域中的屬性名稱 |
scope | false | String | 指定將構造出的URL結果保存在哪一個域中 |
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!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>JSTL方式</h4> <c:url var="i" value="/jstl/choose.jsp" scope="request" context="/day13"> <c:param name="username" value="xiaofeng"></c:param> </c:url> <c:set var="s" value="劉勳" scope="session"></c:set> <a href="${ i }">choose</a> <br> i= ${i } <br> <% String url = "/day12/index.jsp"; url = response.encodeURL(url); %> <!-- 將/day8/index.jsp 進行url重寫。保存page範圍 myurl中 --> <c:url value="/index.jsp" context="/day13" var="myurl" scope="page" /> url= <%=url %> <br> myurl= ${myurl } <br> <!-- 經過c:url 結合 c:param 對中文完畢URL編碼 --> <c:url value="/login" context="/day13" var="myurl2" scope="page"> <c:param name="username" value="張三"></c:param> </c:url> myurl2= ${myurl2 } <br> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!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> <c:out value="${s }"></c:out> <h4>獲取參數</h4> <%= request.getParameter("username") %> <h4>傳統方式</h4> <% int a = 10; if(a >= 10 ){ out.print("a >= 10"); }else if(a < 10){ out.print("a < 10"); }else{ out.print("其它"); } %> <h4>JSTL方式</h4> <c:set var="i" value="10" scope="page"></c:set> <c:choose> <c:when test="${ i ge 10 }"> i >= 10 </c:when> <c:when test="${ i lt 10 }"> i < 10 </c:when> <c:otherwise> 其它 </c:otherwise> </c:choose> </body> </html>禁用瀏覽器的cookie後。執行例如如下:
屬性名 | 是否支持EL | 屬性類型 | 屬性描寫敘述 |
url | true | String | 指定要轉發或重定向到的目標資源的URL地址 |
context | true | String | 當要使用相對路徑重定向到同一個server下的其它WEB應用程序中的 資源時,context屬性指定其它WEB應用程序的名稱 |
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!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>JSTL方式</h4> <c:redirect url="/jstl/choose.jsp" context="/day13"> <c:param name="username" value="furong"></c:param> </c:redirect> </body> </html>
fn:indexOf函數接收兩個字符串類型的參數。假設第一個參數字符串中包括第二個參數字符串,那麼不管第二個參數字符串在第一個參數字符串中出現幾回。fn:indexOf函數老是返回第一次出現的索引值;假設第一個參數中不包括第二個參數。則fn:indexOf函數返回-1。假設第二個參數爲空字符串,則fn:indexOf函數老是返回0。sql
fn:contains函數在比較兩個字符串是否相等時是大寫和小寫敏感的。express
假設第二個參數爲空字符串。則fn:startsWith函數老是返回true。好比:apache
fn:substring函數接收三個參數,第一個參數是用於指定要操做的源字符串。第二個參數是用於指定截取子字符串開始的索引值,第三個參數是用於指定截取子字符串結束的索引值,第二個參數和第三個參數都是int類型,其值都從0開始好比:數組
package cn.itcast.el; public class ElDemo1 { public static String sayHello(String name){ return "hello "+name; } }在WebRoot/WEB-INF下新建myfn的tld文件 並進行配置:
<?xml version="1.0" encoding="UTF-8"?> <taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"> <tlib-version>1.0</tlib-version> <short-name>myfn</short-name> <uri>http://www.itcast.cn/1110/myfn</uri> <!-- 配置本身定義的EL函數 --> <function> <!-- 配置方法名稱 --> <name>sayHi</name> <!-- 方法所在的類 --> <function-class>cn.itcast.el.ElDemo1</function-class> <!-- 配置方法的簽名 --> <function-signature>java.lang.String sayHello(java.lang.String)</function-signature> </function> </taglib>在WebRoot根文件夾下新建el文件夾,在裏面新建demo.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> <%@ taglib uri="http://www.itcast.cn/1110/myfn" prefix="myfn" %> <!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> ${ fn:length("abcdefg") } ${ fn:toUpperCase("abcdefg") } ${ myfn:sayHi("小風") } </body> </html>
實現SimpleTag接口的標籤一般稱爲簡單標籤。瀏覽器
在doTag方法中可以拋出javax.servlet.jsp.SkipPageException異常。用於通知WEB容器再也不運行JSP頁面中位於結束標記後面的內容,這等效於在傳統標籤的doEndTag方法中返回Tag.SKIP_PAGE常量的狀況。緩存
假設標籤的屬性值是EL表達式。則WEB容器首先計算表達式的值。而後把值傳遞給標籤處理器對象。tomcat
好比:
並提供set方法。頁面的屬性與類中的屬性名稱必須一樣。
元素名 | 是否必須指定 | 描寫敘述 |
description | 否 | 用於指定屬性的描寫敘述信息 |
name | 是 | 用於指定屬性的名稱。屬性名稱是大寫和小寫敏感的,並且不能以jsp、 _jsp、java和sun開頭 |
required | 否 | 用於指定在JSP頁面中調用本身定義標籤時是否必須設置這個屬性。 其 |
rtexprvalue | 否 | rtexprvalue是runtime expression value(執行時表達式)的英文簡寫, 用於指定屬性值是一個靜態值或動態值。其取值包含true和false,默認值 是false。false表示僅僅能爲該屬性指定靜態文本值,好比"123"; true表示可 覺得該屬性指定一個JSP動態元素,動態元素的結果做爲屬性值。好比 JSP表達式<%=value %> |
type | 否 | 用於指定屬性值的Java類型。 默認是String |
package cn.itcast.tag; import java.io.IOException; import javax.servlet.jsp.JspContext; import javax.servlet.jsp.JspException; import javax.servlet.jsp.PageContext; import javax.servlet.jsp.tagext.SimpleTagSupport; /** * 對外輸出Hello * @author Administrator * */ public class TagDemo1 extends SimpleTagSupport{ private PageContext pc; public void doTag() throws JspException, IOException { pc.getOut().write("Hello"); } /** * server默認先運行該方法 */ public void setJspContext(JspContext pc) { this.pc = (PageContext) pc; } }TagDemo2.java (有標籤體 處理標籤體內容)
package cn.itcast.tag; import java.io.IOException; import java.io.StringWriter; import javax.servlet.jsp.JspContext; import javax.servlet.jsp.JspException; import javax.servlet.jsp.PageContext; import javax.servlet.jsp.tagext.JspFragment; import javax.servlet.jsp.tagext.SimpleTagSupport; /** * 帶有標籤主體 * @author Administrator * */ public class TagDemo2 extends SimpleTagSupport{ private PageContext pc; public void doTag() throws JspException, IOException { JspFragment jf = getJspBody(); StringWriter sw = new StringWriter(); //經過invoke方法將標籤體內容寫入到參數Writer對象sw中 jf.invoke(sw); // 獲取標籤體內容 String content = sw.toString().toUpperCase(); pc.getOut().print(content); } public void setJspContext(JspContext pc) { this.pc = (PageContext)pc; } }TagDemo3.java (有屬性 有標籤體的本身定義標籤)
package cn.itcast.tag; import java.io.IOException; import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.SimpleTagSupport; /** * 類似<c:if>標籤,帶有屬性的 * @author Administrator * */ public class TagDemo3 extends SimpleTagSupport{ private boolean test; public void setTest(boolean test) { this.test = test; } public void doTag() throws JspException, IOException { if(test){ getJspBody().invoke(null); } } }
<?xml version="1.0" encoding="UTF-8"?> <taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"> <tlib-version>1.0</tlib-version> <short-name>myc</short-name> <uri>http://www.itcast.cn/1110/myc</uri> <!-- 配置本身定義標籤 --> <tag> <!-- 配置標籤名稱 --> <name>print</name> <!-- 配置標籤的類 --> <tag-class>cn.itcast.tag.TagDemo1</tag-class> <!-- 配置標籤主體 --> <body-content>empty</body-content> </tag> <!-- 配置本身定義標籤 --> <tag> <!-- 配置標籤名稱 --> <name>out</name> <!-- 配置標籤的類 --> <tag-class>cn.itcast.tag.TagDemo2</tag-class> <!-- 配置標籤主體 --> <body-content>scriptless</body-content> </tag> <!-- 配置本身定義標籤 --> <tag> <!-- 配置標籤名稱 --> <name>if</name> <!-- 配置標籤的類 --> <tag-class>cn.itcast.tag.TagDemo3</tag-class> <!-- 配置標籤主體 --> <body-content>scriptless</body-content> <!-- 配置屬性 --> <attribute> <!-- 配置屬性名稱 --> <name>test</name> <!-- 屬性是不是必須的 --> <required>true</required> <!-- 是否支持EL表達式 --> <rtexprvalue>true</rtexprvalue> <!-- 屬性的類型 --> <type>boolean</type> </attribute> </tag> </taglib>在WebRoot下新建tag目錄。新建tag.jsp 測試本身定義標籤內容
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://www.itcast.cn/1110/myc" prefix="myc" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!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> <myc:print/> <myc:out> liuxun1993 </myc:out> <c:set var="i" value="10"></c:set> <myc:if test="${ i eq 10 }"> 美美 </myc:if> </body> </html>啓動server。執行結果例如如下: