首先,感謝大家的關(guān)注,下面我來繼續(xù)講解:URL相關(guān)的標(biāo)簽,他們的作用主要是負(fù)責(zé)頁面的導(dǎo)航、重定向、資源的獲得以及參數(shù)的傳遞等等,他們有:
l <c:import>
l <c:redirect>
l <c:url>
l <c:param>
<c:import>
作用:導(dǎo)入一個url的資源,相當(dāng)于jsp 中的<jsp:include page=”path”>標(biāo)簽,同樣也可以把參數(shù)傳遞到被導(dǎo)入的頁面。
語法:a、資源的內(nèi)容使用string對象向外暴露
<c:import url=”url” [context=”context”]
[var=”varName”] [scope=”{page|request|session|application}”]
[charEncoding=”charEncoding”]>
Optional body content for <c:param> subtags
</c:import>
b、資源的內(nèi)容使用redirect對象向外暴露
<c:import url=”url” [context=”context”]
varReader=”varReaderName”
[charEncoding=”charEncoding”]>
Body content where varReader is consumed by another action
</c:import>
舉例:c_import.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<html>
<head>
<title>JSTL:c:import的使用</title>
</head>
<body bgcolor="#FFFFFF">
<h3>絕對路徑 URL</h3>
<blockquote>
<ex:escapeHtml>
<c:import url="http://127.0.0.1:8080/ch12/footer.jsp"/>
</ex:escapeHtml>
</blockquote>
<h3>相對路徑并且傳遞參數(shù)到指定的URL</h3>
<blockquote>
<c:import url="footer.jsp" charEncoding="gb2312">
<c:param name="userName" value="hellking"/>
</c:import>
</blockquote>
</body>
</html>
<c:redirect>
作用:把客戶的請求發(fā)送到另一個資源,相當(dāng)于jsp中的<% request.sendRedirect(“other.jsp”)%>或者servlet中的RequestDispatch.forward(“other.jsp”)的功能。
語法:a、沒有body的情況
<c:redirect url=”value” [context=”context”]/>
b、有body,在body 中查詢指定的參數(shù)
<c:redirect url=”value” [context=”context”]>
<c:param> subtags
</c:redirect>
舉例:c:redirect.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<html>
<head>
<title>JSTL:c:redirect的使用</title>
</head>
<body bgcolor="#cc99cc">
<c:url value="footer.jsp" var="nextpage"><c:param name="userName" value="hellking"/></c:url>
<c:redirect url="${nextpage}"/>
</body>
</html>
<c:url>
作用:用于構(gòu)造URL,主要的用途是URL的重寫。
語法:a、沒有body的情況
<c:url value=”value” [context=”context”]
[var=”varName”] [scope=”{page|request|session|application}”]/>
b、有body ,并在body 中有重寫的參數(shù)
<c:url value=”value” [context=”context”]
[var=”varName”] [scope=”{page|request|session|application}”]>
<c:param> subtags
</c:url>
舉例:c_url.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<html>
<head>
<title>JSTL c:url 的使用</title>
</head>
<body bgcolor="#FFFFFF">
<c:url var="footer" value="footer.jsp" scope="page">
<c:param name="id" value="hellking"/>
</c:url>
<c:out value="${footer}"/>
<br>另一種沒有參數(shù)的URL<br>
<c:url value="footer.jsp"/>
</body>
</html>
<c:param>
作用:它是在<c:import>,<c:redirectt>,<c:url>中添加請求的參數(shù)。和一般的參數(shù)沒什么區(qū)別。
語法:a、參數(shù)的值使用value屬性指定
<c:param name=”name” value=”value”/>
b、參數(shù)的值在body 中指定
<c:param name=”name”>
參數(shù)值
</c:param>
舉例:c_param.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<html>
<head>
<title>JSTL c:param的使用</title>
</head>
<body bgcolor="#FFFFFF">
<c:redirect url="footer.jsp">
<c:param name="userName">
hellking
</c:param>
</c:redirect>
</body>
</html>