ELtest.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/myfun/ELFunction" prefix="mfn" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>EL 测试页面</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<h1>EL表达式测试页面</h1>
比较25和35,其中的最大值是:${mfn:max(25,35)}<br/>
<%
Map names = new HashMap();
names.put("one","张三");
names.put("two", "李四");
request.setAttribute("ns", names);
%>
<!-- ${names.get(0) } ===> out.write(names.get(0))-->
姓名1:${requestScope.ns.one} <br>
姓名2:${requestScope.ns["two"]}<br>
<form action="ch07/result.jsp" method="post">
昵称:<input type="text" name="name"/><br/>
城市:<input type="text" name="city"/><br/>
开发语言:<input type="checkbox" name="lg" value="C#"/>C#
<input type="checkbox" name="lg" value="Java"/>Java
<input type="checkbox" name="lg" value="HTML"/>HTML
<input type="checkbox" name="lg" value="SQL"/>SQL
<input type="checkbox" name="lg" value="JavaScript"/>JavaScript<br/>
<input type="submit" value="提交"/>
</form>
<hr/>
设置变量或属性
<c:set var="num" value="${100+1}" scope="session"/><br/>
<c:set var="num1" scope="session">
${4+5}
</c:set>
输出变量值
num: <c:out value="${num}" />
num1: <c:out value="${num1}" /><br/>
移除变量:
<c:remove var="num"/>
<c:remove var="num1"/><br/>
<c:if test="${num==100}" var="isnum">
<h4>num的值是100</h4>
</c:if>
<c:if test="${num!=100}" var="isnum1" scope="page">
<h4>num的值是不是100 </h4>
</c:if>
<hr/>
<%
String [] numbers={"232","213","fdr","2w3","4e2"};
request.setAttribute("NUMS", numbers);
%>
<c:set var="sp" value="ed,swe,ddd;aswe:desw|sswe"/>
<!-- 数组或集合 使用 forEach进行迭代 -->
<c:forEach var="n" items="${NUMS}" varStatus="s">
索引:<c:out value="${s.index}" />
<c:out value="${n}" /> 次数<c:out value="${s.count}"/><br/>
</c:forEach>
---------------------------<br/>
<!-- 字符串数据 使用 forTokens进行迭代 -->
<c:forTokens var="t" items="${sp}" delims=",;:|">
<c:out value="${t}" /><br/>
</c:forTokens>
</body>
</html>
I18N.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'I18N.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<h2>格式化标签示例</h2>. <br>
<fmt:setLocale value="zh_CN" scope="application"/>
中文数字格式:
<fmt:formatNumber var="fn1" value="45.6" type="currency"/>
<c:out value="${fn1}"/>
<br/>
<!-- formatNumber: type 取值有三个 number数字;currency货币 percent 百分数格式 -->
<fmt:setLocale value="en_US"/>
美英格式:
<fmt:formatNumber var="fn2" value="12.3" type="currency"/>
<c:out value="${fn2}"/>
<br/>
<fmt:formatNumber var="fn3" value="123568758" type="number"/>
数字格式:<c:out value="${fn3}"/>
<br/>
<fmt:formatNumber var="fn4" value="123.45" type="percent"/>
百分数格式:<c:out value="${fn4}"/>
<br/>
<hr/>
<h3>时间格式化</h3>
<c:set var="d" value="<%=new java.util.Date() %>"/>
格式1:<fmt:formatDate value="${d}" pattern="yyyy年MM月dd日"
type="date" dateStyle="full"/><br/>
格式2:<fmt:formatDate value="${d}" pattern="HH:mm:ss"
type="time" dateStyle="full"/><br/>
格式3:<fmt:formatDate value="${d}" pattern="yyyy年MM月dd日 HH:mm:ss"
type="both" dateStyle="full"/><br/>
格式4:<fmt:formatDate value="${d}" type="both"
timeZone="GMT" dateStyle="full"/><br/>
<h3>消息格式</h3>
<%
request.setAttribute("num",new Double(123.45));
%>
<fmt:bundle basename="Resource"><!-- 绑定属性文件 -->
<!-- 通过key取得value数据 -->
<fmt:message key="str">
<fmt:param value="zhangsan"/>
<fmt:param value="${d}"/>
<fmt:param value="${d}"/>
<fmt:param value="${num}"/>
</fmt:message>
</fmt:bundle>
</body>
</html>
sqljstl.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/sql" prefix="sql" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>数据库标签示例</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
数据库标签示例. <br>
<!-- 数据源标签 -->
<sql:setDataSource var="ds"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306/news"
user="root" password="root" scope="application"/>
<c:catch var="e">
<sql:query var="us" dataSource="${ds}">
select * from users
</sql:query>
<table border="1">
<c:forEach var="u" items="${us.rows}">
<tr>
<td> <c:out value="${u.uid}"/> </td>
<td> <c:out value="${u.uname}"/> </td>
<td> <c:out value="${u.upwd}"/> </td>
</tr>
</c:forEach>
</table>
</c:catch>
添加数据的执行情况: <c:out value="${r2}"/><br/>
<c:out value="${e}"/>
</body>
</html>