<c:import>,<c:redirect>,<c:url>

来源:互联网 发布:话剧场景 知乎 编辑:程序博客网 时间:2024/06/15 21:13


<c:import>作用:导入一个url的资源,相当于jsp 中的<jsp:include page=”path”>标签,同样也可以把参数传递到被导入的页面。语法:a、资源的内容使用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、资源的内容使用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>相对路径并且传递参数到指定的URL</h3><blockquote><c:import url="footer.jsp" charEncoding="gb2312"><c:param name="userName" value="hellking"/></c:import></blockquote></body></html><c:redirect>作用:把客户的请求发送到另一个资源,相当于jsp中的<% request.sendRedirect(“other.jsp”)%>或者servlet中的RequestDispatch.forward(“other.jsp”)的功能。语法:a、没有body的情况              <c:redirect url=”value” [context=”context”]/>      b、有body,在body 中查询指定的参数              <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>作用:用于构造URL,主要的用途是URL的重写。语法:a、没有body的情况              <c:url value=”value” [context=”context”][var=”varName”] [scope=”{page|request|session|application}”]/>      b、有body ,并在body 中有重写的参数              <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>另一种没有参数的URL<br><c:url value="footer.jsp"/></body></html><c:param>作用:它是在<c:import>,<c:redirectt>,<c:url>中添加请求的参数。和一般的参数没什么区别。语法:a、参数的值使用value属性指定              <c:param name=”name” value=”value”/>      b、参数的值在body 中指定              <c:param name=”name”>                    参数值              </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>
http://hi.baidu.com/fsyudar/blog/item/ec9143d929f5c1ccb6fd48ca.html






5.6.3  <c:redirect>标签<c:redirect>标签把请求重定向到其他Web资源,本书第5章的5.7节(重定向)已经介绍了重定向的概念。<c:redirect>标签的基本语法为:    <c:redirect url="目标Web资源的URL" /> 例如以下代码把请求重定向到同一个Web应用中的target.jsp:    <c:redirect url="dir2/target.jsp" > 例如以下代码把请求重定向到JavaThinker网站的index.jsp:    <c:redirect url="http://www.javathinker.org/index.jsp" > 在<c:redirect>标签中也可以设置context属性,还可以加入<c:param>子标签。例如以下代码把请求重定向到helloapp1应用中的target.jsp,并且提供了num1和num2请求参数:    <c:redirect url="/dir1/dir2/target.jsp" context="/helloapp1" >       <c:param name="num1" value="10" />       <c:param name="num2" value="20" />     </c:redirect> 








原创粉丝点击