小峰servlet/jsp(7)jstl国际化标签库、sql标签库等
一、jstl国际化标签库:
fmt:setLocale 设定用户所在的区域;
fmt:formatDate 对日期进行格式化
fmt:requestEncoding 设置所有的请求编码;
fmt:bundle fmt:message 读取国际化资源;
fmt:formatNumber 格式化数字;
fmt:timeZone 设置临时时区
fmt:setLocale:
<body>
<%
pageContext.setAttribute("date",new Date());
%>
中文日期:
<fmt:setLocale value="zh_CN"/>
<fmt:formatDate value="${date }"/>
<hr/>
英文日期:
<fmt:setLocale value="en_US"/>
<fmt:formatDate value="${date }"/>
</body>

fmt:requestEncoding:
<body>
<fmt:requestEncoding value="UTF-8"/>
</body>
fmt:bundle; fmt:message:
资源文件:

info_en_US.properties:
name=xiaofeng
info=Current user{0}:Welcome to use our system
info_zh_CN.properties:
name=\u5c0f\u950b
info=\u5f53\u524d\u7528\u6237{0}:\u6b22\u8fce\u4f7f\u7528\u672c\u7cfb\u7edf
<body>
<fmt:setLocale value="zh_CN"/>
<fmt:bundle basename="info">
<fmt:message key="name" var="userName"/>
</fmt:bundle>
<h2>姓名:${userName }</h2>
<fmt:bundle basename="info">
<fmt:message key="info" var="infomation">
<fmt:param value="<font color='red'>小锋</font>"/>
</fmt:message>
</fmt:bundle>
<h2>信息:${infomation }</h2>
<hr/>
<fmt:setLocale value="en_US"/>
<fmt:bundle basename="info">
<fmt:message key="name" var="userName"/>
</fmt:bundle>
<h2>姓名:${userName }</h2>
<fmt:bundle basename="info">
<fmt:message key="info" var="infomation">
<fmt:param value="<font color='red'>小锋</font>"/>
</fmt:message>
</fmt:bundle>
<h2>信息:${infomation }</h2>
</body>
//<fmt:param value="<font color='red'>小锋</font>"/>是为properties中的占位符动态塞数据;

fmt:formatNumber:
<body>
<!-- value:数值 ; type:数值类型; pattern:格式 -->
<fmt:formatNumber value="12" type="currency" pattern="$.00"/>
<fmt:formatNumber value="12" type="currency" pattern="$.0#"/>
<fmt:formatNumber value="1234567890" type="currency"/>
<fmt:formatNumber value="123456.7891" pattern="#,#00.0#"/>
</body>

fmt:formatDate:
<body>
<!-- value:数值 ; type:数值类型; pattern:格式 -->
<%
Date date=new Date();
pageContext.setAttribute("date",date);
%>
<fmt:formatDate value="${date }" pattern="yyyy-MM-dd HH:mm:ss"/>
<hr/>
<fmt:formatDate value="${date }" pattern="yyyy-MM-dd"/>
</body>

fmt:timeZone:
<body>
<!-- value:数值 ; type:数值类型; pattern:格式 -->
<%
Date date=new Date();
pageContext.setAttribute("date",date);
%>
当前时间:<fmt:formatDate value="${date }" pattern="yyyy-MM-dd HH:mm:ss"/>
<hr/>
格林尼治时间:
<fmt:timeZone value="GMT">
<fmt:formatDate value="${date }" pattern="yyyy-MM-dd HH:mm:ss"/>
</fmt:timeZone>
</body>

二、jstl SQL标签库:
sql:setDataSource 设置JDBC连接;
sql:query 数据库查询操作
sql:update 数据库添加、修改、删除操作;
sql:transaction 数据库事务
sql:setDataSource/sql:query:
数据库中存在这样的表:t_student:

jsp页面要引入:<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>设置JDBC连接</h1>
<sql:setDataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/db_jstl" user="root" password="123456" />
<sql:query var="result">
select * from t_student;
</sql:query>
<h2>总记录数:${result.rowCount }</h2>
<table>
<tr>
<th>编号</th>
<th>学号</th>
<th>姓名</th>
<th>出生日期</th>
<th>性别</th>
</tr>
<c:forEach var="student" items="${result.rows }">
<tr>
<td>${student.id }</td>
<td>${student.stuNo }</td>
<td>${student.stuName }</td>
<td>${student.birthday }</td>
<td>${student.sex }</td>
</tr>
</c:forEach>
</table>
</body>
</html>
访问展示:
sql:update:
增:
<body>
<h1>设置JDBC连接</h1>
<sql:setDataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/db_jstl" user="root" password="123456"/>
<h1>添加数据</h1>
<sql:update var="result" >
insert into t_student values(null,"008","草泥马","1991-1-1","男");
</sql:update>
</body>
改:
<body>
<h1>设置JDBC连接</h1>
<sql:setDataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/db_jstl" user="root" password="123456"/>
<h1>修改数据</h1>
<sql:update var="result" >
update t_student set stuNo="010",sex="未知" where id=6
</sql:update>
</body>
删:
<body>
<h1>设置JDBC连接</h1>
<sql:setDataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/db_jstl" user="root" password="123456"/>
<h1>删除数据</h1>
<sql:update var="result" >
delete from t_student where id=6
</sql:update>
</body>
sql:transcation:
<body>
<h1>设置JDBC连接</h1>
<sql:setDataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/db_jstl" user="root" password="123456"/>
<h1>事务</h1>
<sql:transaction>
<sql:update var="result" >
insert into t_student values(null,"008","草泥马","1991-1-1","男");
</sql:update>
</sql:transaction>
</body>
三、jstl xml标签库:
x:parse 解析xml;
x:out 输出xml文件的内容
x:set 把xml读取的内容保存到指定的属性范围
x:if 判断指定路径的内容是否符合判断的条件;
x:choose/x:when/x:otherwise 多条件判断
x:forEach 遍历
需要引入xalan.jar;
jsp文件需要引入:<%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x"%>
有这样两个xml文件,usersInfo.xml; usersInfo2.xml:
usersInfo.xml:
<?xml version="1.0" encoding="UTF-8"?>
<users>
<user>
<name id="n1">张三</name>
<birthday>2011-1-1</birthday>
</user>
</users>
usersInfo2.xml:
<?xml version="1.0" encoding="UTF-8"?>
<users>
<user>
<name id="n1">张三</name>
<birthday>2011-1-1</birthday>
</user>
<user>
<name id="n2">王五</name>
<birthday>2011-1-2</birthday>
</user>
<user>
<name id="n3">赵六</name>
<birthday>2011-1-3</birthday>
</user>
</users>
文件存放路径:

1)x:parse x:out
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<c:import var="usersInfo" url="usersInfo.xml" charEncoding="UTF-8"/>
<x:parse var="usersInfoXml" doc="${usersInfo }"/> <h2>姓名:<x:out select="$usersInfoXml/users/user/name"/>
(ID:<x:out select="$usersInfoXml/users/user/name/@id"/>)</h2>
<h2>出生日期:<x:out select="$usersInfoXml/users/user/birthday"/></h2>
</body>
</html>

2) x:set
<body>
<c:import var="usersInfo" url="usersInfo.xml" charEncoding="UTF-8"/>
<x:parse var="usersInfoXml" doc="${usersInfo }"/> <x:set var="userInfoXml" select="$usersInfoXml/users/user"/>
<h2>姓名:<x:out select="$userInfoXml/name"/></h2>
</body>
3) x:if
<body>
<c:import var="usersInfo" url="usersInfo.xml" charEncoding="UTF-8"/>
<x:parse var="usersInfoXml" doc="${usersInfo }"/>
<x:if select="$usersInfoXml/users/user/name/@id='n1'">
<h2>有编号是n1的user信息</h2>
</x:if>
</body>
4) x:choose/x:when/x:otherwise
<body>
<c:import var="usersInfo" url="usersInfo.xml" charEncoding="UTF-8"/>
<x:parse var="usersInfoXml" doc="${usersInfo }"/>
<x:choose>
<x:when select="$usersInfoXml/users/user/name/@id='n2'">
<h2>有编号是n2的user信息</h2>
</x:when>
<x:otherwise>
<h2>没有编号是n2的user信息</h2>
</x:otherwise>
</x:choose>
</body>
5) x:forEach:
<body>
<c:import var="usersInfo" url="usersInfo2.xml" charEncoding="UTF-8"/>
<x:parse var="usersInfoXml" doc="${usersInfo }"/>
<x:forEach select="$usersInfoXml/users/user" var="userInfoXml">
<h2>姓名:<x:out select="$userInfoXml/name"/> 出生日期:<x:out select="$userInfoXml/birthday"/></h2>
<hr/>
</x:forEach>
</body>

四、jstl函数标签库:
jsp页面需要引入:
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
pageContext.setAttribute("info","www.java1234.com");
%>
<h2>查找java1234位置:${fn:indexOf(info,"java1234")}</h2>
<h2>判断java1234是否存在:${fn:contains(info,"java1234")}</h2>
<h2>截取:${fn:substring(info,0,5)}</h2>
<h2>拆分:${fn:split(info,".")[1]}</h2>
</body>
</html>
页面展示:

函数标签一些:
<c:if test="${fun:length(operation.rangeList) > 0}">
小峰servlet/jsp(7)jstl国际化标签库、sql标签库等的更多相关文章
- 小峰servlet/jsp(5)jsp自定义标签
一.自定义标签helloworld: 二.自定义有属性的标签: HelloWorldTag.java:继承TagSupport: package com.java1234.tag; import ja ...
- 小峰servlet/jsp(1)
一.scriptlet标签: 通过scriptlet标签我们可以可以在jsp理嵌入java代码: 第一种:<%! %> 可以在里面定义全局变量.方法.类: 第二种:<% %> ...
- 小峰servlet/jsp(6)jstl核心标签库
一.引入jstl 需要jstl.jar;standard.jar; 二.jstl核心标签库: c:out 内容输出标签; c:set 用来设置4种属性范围值的标签: c:re ...
- 小峰servlet/jsp(3)登陆功能实现
一.User模型: User.java: package com.java1234.model; public class User { private int id; private String ...
- 小峰servlet/jsp(4)EL表达式
一.EL表达式内置对象: 二.EL表达式访问4种范围属性: 寻找值的顺序: page-->request-->session-->application; 三.EL表达式接收请求参数 ...
- 小峰servlet/jsp(2)
一.jsp javaBean组件引入 <jsp:useBean id="实例化对象名称" scope="保存范围" class="类完整名称&q ...
- JSP中 JSTL和EL标签的使用
使用JSTL前的准备 想要使用JSTL,首先需要给工程导入JSTL的包(JSTL.jar和standard.jar). JSTL简介 JSP标准标签库(JSTL)是一个JSP标签集合,它封装了JSP应 ...
- Java Servlet(十):JSTL核心标签库
JSTL全名称:JaveServer Pages Standard Tag Library.JSTL是由JCP(Java Community Process)所定制的标准规范,它主要提供给Java W ...
- servlet&jsp高级:第三部分
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
随机推荐
- weblogic控制台定制不同权限的用户
安装weblogic并创建域(domain)的时候,会默认创建一个用户,此用户为管理员,也就是权限最大的.只有这样一个用户,用起来很不安全,因为一个测试环境,好多人在用,经常会有人修改上面的数据源等关 ...
- Mac自带的本地服务器的使用
1. 打开终端,开启Apache: //开启apache: sudo apachectl start //重启apache: sudo apachectl restart //关闭apache: su ...
- iOS使用UIWebView遇到Error Domain=WebKitErrorDomain Code=101 “The operation couldn’t be completed. (WebKitErrorDomain error 101
现在在接触iOS开发,今天在调试一个界面加载web页面的问题,发现死活无法加载,浏览器里能正常打开,加上相应代码之后得到了错误信息为: 2013-04-18 15:05:06.446 Client_D ...
- 网络端口(port)
在同一个网络地址上,为了区分使用相同协议的不同应用程序,可以为不同的应用程序分配一个数字编号,称为端口号(port). 取值范围:0-65535 IANA(Internet Assigned Numb ...
- Translate Exercises(4)
周五翻译课记录. ---------------------------------- (1)and it is imagined by many that the operations of the ...
- mysql 试图
关系型数据库中的数据是由一张一张的二维关系表所组成,简单的单表查询只需要遍历一个表,而复杂的多表查询需要将多个表连接起来进行查询任务.对于复杂的查询事件,每次查询都需要编写MySQL代码效率低下.为了 ...
- Locust 其他协议
Locust 是基于HTTP作为主要目标构建的,但是他同样可以扩展其他的协议,接受请求与获得返回.在编写的客户端的时候,我们就要使用到最常使用的 request_success 和 request_f ...
- Mac下百度网盘破解
Mac版百度网盘破解 先下载正版的百度网盘 打开终端输入命令 cd ~/Downloads && git clone https://github.com/CodeTips/Baid ...
- 你在AutoHotKey面前居然敢比调音量 - imsoft.cnblogs
当你正在电脑游戏中酣战之际.或者正沉浸在动作大片紧张激烈的情节中.或者正在全神贯注的聆听优美动听音乐……,在这些场景中,如果你需要迅速对音量进行调节(例如增大减小音量,或者静音)怎么办?难道返回Win ...
- Oracle查询今天、昨天、本周、上周、本月、上月数据
查询今天数据: SELECT COUNT(1) FROM T_CALL_RECORDS WHERE TO_CHAR(T_RKSJ,'YYYY-MM-DD')=TO_CHAR(SYSDATE,'YYYY ...