天天看點

JSP-JSTL-import、redirect、url處理、常用函數importredirectURL常用函數

版權聲明:本文為部落客原創文章,轉載請注明出處。 https://blog.csdn.net/twilight_karl/article/details/75804798

import

<import url=”” context=”” var=”” scope=”” charEncoding=”” varReader=”“></c:import>

包含另一個 JSP 頁 面到本頁面來

  • url 檔案的url
  • var 導入的資料儲存到var中
  • scope var的儲存位置
  • charEncoding 編碼方式
  • 直接導入外部url
<c:import url="http://www.imooc.com"></c:import>           
  • 導入目前項目下的檔案
<c:import url="import.txt" charEncoding="utf-8" var="txt" scope="session"></c:import>
  <c:out value="#${sessionScope.txt }"></c:out>           

-導入另一個項目中的檔案。需要更改context.xml檔案。将添加屬性

crossContext="true"

<c:import url="/hello.html" context="/Train_HTML"></c:import>           

redirect

頁面重定向

- url 指定頁面的位址,

- context其他web應用的頁面

<c:redirect url="OutTest.jsp">
        <c:param name="username">tom</c:param>
        <c:param name="password">123</c:param>
    </c:redirect>

// http://localhost:8080/Test/JSTLTest/import.txt?username=tom&password=123           

URL

動态生成一個String類型的URL,與c:param一起使用

- value url路徑

- var 将url儲存在變量中

<c:url value="http://localhost:8080/Test/URLTest.jsp" var="urlstr">
        <c:param name="data" value="${data }"></c:param>
    </c:url>
    <a href="${urlstr }">url</a>
// http://localhost:8080/Test/URLTest.jsp?data=sss           

常用函數

使用JSTL函數需要導入JSTL函數标簽:

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>           

常用函數羅列如下:

函數 作用
length() 傳回長度
replace(text, ‘-‘,’.’) 替換一個字元串與另一個字元串的比對
split(str,”.”) 分割字元串,儲存在數組中
startsWith(str1,str2) 是否以指定字元串開始
endWith(str1,str2) 判斷str1是否以str2結尾
substring(str,begin,end) 子串
toLowerCase() 小寫
toUpperCase() 大寫
trim() 去除兩邊空格
contains(strlong,str) 判斷子串
containsIgnreCase(strLong,str) 判斷子串,忽略大小寫
indexOf(str1,str2) 判斷str2出現的index值
escapeXml() 忽略用于XML标記的字元。