fn.endsWith标签用法实例



JSTL的fn.endsWith标签用法实例:

fn_endsWith.jsp文件:

<%@ page language=”java” import=”java.util.*” pageEncoding=”utf-8″%>
<%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c”%>
<%@ taglib uri=”http://java.sun.com/jsp/jstl/functions” prefix=”fn”%>
<%@ page import=”java.io.*” %>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html>
<head>
<title>My JSP ‘fn_endsWith.jsp’ starting page</title>
</head>
<body>
<%
//把D盘下的文件放入request对象中
request.setAttribute(“fileList”, new File(“d:\\”).listFiles());
%>
<table border=”1″ width=”70%”>
<tr class=”title”>
<td>文件名</td>
<td>文件类型</td>
</tr>
<c:forEach var=”file” items=”${ fileList }”>
<tr>
<td>${ file.name }</td>
<td>
<c:choose>
<c:when test=”${ file.directory }”>文件夹</c:when>
<c:otherwise>
<c:if test=”${ fn:endsWith(file.name, ‘.jpg’) }”>JPG类型图片</c:if>
<c:if test=”${ fn:endsWith(file.name, ‘.exe’) }”>应用程序</c:if>
<c:if test=”${ fn:endsWith(file.name, ‘.gif’) }”>GIF类型图片</c:if>
<c:if test=”${ fn:endsWith(file.name, ‘.txt’) }”>记事本文件</c:if>
<c:if test=”${ fn:endsWith(file.name, ‘.doc’) }”>WORD文档</c:if>
<c:if test=”${ fn:endsWith(file.name, ‘.xls’) }”>Excel表格</c:if>
<c:if test=”${ fn:endsWith(file.name, ‘.log’) }”>LOG日志文件</c:if>
<c:if test=”${ fn:endsWith(file.name, ‘.sql’) }”>SQL数据库脚本文件</c:if>
<c:if test=”${ fn:endsWith(file.name, ‘.rar’) }”>压缩文件</c:if>
</c:otherwise>
</c:choose>
</td>
</tr>
</c:forEach>
</table>
</body>
</html>