天天看點

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

<c:import>
浣????瀵煎?ヤ?涓?url??璧?婧?锛??稿?浜?jsp 涓???<jsp:include page=??path??>??绛撅????蜂???浠ユ?????頒????拌?瀵煎?ョ??椤甸????
璇?娉?锛?a??璧?婧?????瀹逛嬌??tring瀵矽薄??澶??撮??              <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??璧?婧?????瀹逛嬌??edirect瀵矽薄??澶??撮??              <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??浣跨??lt;/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锛???ody 涓??ヨ?㈡??瀹???????              <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??浣跨??lt;/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 锛?骞跺??ody 涓?????????????              <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??浣跨??lt;/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>
浣????瀹?????lt;c:import>锛?<c:redirectt>锛?<c:url>涓?娣誨??璇鋒??????般????涓????????版病浠?涔??哄????
璇?娉?锛?a?????扮???間嬌??alue灞??ф??瀹?
              <c:param name=??name?? value=??value??/>
      b?????扮???煎??ody 涓???瀹?
              <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??浣跨??lt;/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" /> 

渚?濡?浠ヤ?浠g????璇鋒???瀹????闆??涓?涓?Web搴??ㄤ腑??target.jsp锛?

    <c:redirect url="dir2/target.jsp" > 

渚?濡?浠ヤ?浠g????璇鋒???瀹?????avaThinker缃?绔???index.jsp锛?

    <c:redirect url="http://www.javathinker.org/index.jsp" > 

??lt;c:redirect>??绛句腑涔???浠ヨ?劇疆context灞??э?杩???浠ュ????lt;c:param>瀛???绛俱??渚?濡?浠ヤ?浠g????璇鋒???瀹?????elloapp1搴??ㄤ腑??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>