天天看点

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标记的字符。