一、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"/>&nbsp;出生日期:<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标签库等的更多相关文章

  1. 小峰servlet/jsp(5)jsp自定义标签

    一.自定义标签helloworld: 二.自定义有属性的标签: HelloWorldTag.java:继承TagSupport: package com.java1234.tag; import ja ...

  2. 小峰servlet/jsp(1)

    一.scriptlet标签: 通过scriptlet标签我们可以可以在jsp理嵌入java代码: 第一种:<%! %>  可以在里面定义全局变量.方法.类: 第二种:<% %> ...

  3. 小峰servlet/jsp(6)jstl核心标签库

    一.引入jstl 需要jstl.jar;standard.jar; 二.jstl核心标签库: c:out         内容输出标签; c:set      用来设置4种属性范围值的标签: c:re ...

  4. 小峰servlet/jsp(3)登陆功能实现

    一.User模型: User.java: package com.java1234.model; public class User { private int id; private String ...

  5. 小峰servlet/jsp(4)EL表达式

    一.EL表达式内置对象: 二.EL表达式访问4种范围属性: 寻找值的顺序: page-->request-->session-->application; 三.EL表达式接收请求参数 ...

  6. 小峰servlet/jsp(2)

    一.jsp javaBean组件引入 <jsp:useBean id="实例化对象名称" scope="保存范围" class="类完整名称&q ...

  7. JSP中 JSTL和EL标签的使用

    使用JSTL前的准备 想要使用JSTL,首先需要给工程导入JSTL的包(JSTL.jar和standard.jar). JSTL简介 JSP标准标签库(JSTL)是一个JSP标签集合,它封装了JSP应 ...

  8. Java Servlet(十):JSTL核心标签库

    JSTL全名称:JaveServer Pages Standard Tag Library.JSTL是由JCP(Java Community Process)所定制的标准规范,它主要提供给Java W ...

  9. servlet&jsp高级:第三部分

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

随机推荐

  1. 手把手教你搭建一个Elasticsearch集群

    一.为何要搭建 Elasticsearch 集群 凡事都要讲究个为什么.在搭建集群之前,我们首先先问一句,为什么我们需要搭建集群?它有什么优势呢? (1)高可用性 Elasticsearch 作为一个 ...

  2. Nginx+Tomcat简单集群

    1.软件准备下载Nginx和Tomcat解压到一个目录2.修改Tomcat的端口Tomcat1:修改Server.xmlTomcat2:修改Server.xml3.测试Tomcat是否正常运行分别访问 ...

  3. logback转义符与MDC

    关于MDC的使用,可以结合filter一块使用,将需要串联的上下文的关键信息,通过header进行传递,然后通过配置%X{userId}将信息打印出来. MDC.put("userId&qu ...

  4. Xcode C++ and Objective-C refactoring

    Is there a way to refactor mixed C++/Objective-C code in Xcode ?? I am writing a game using Cocos2D ...

  5. Docker教程-01.安装docker-ce-18.06

    参考文章:http://www.runoob.com/docker/docker-tutorial.html 1.Docker简介 1)Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从 ...

  6. 关于前端的margin

    margin 边界,元素周围生成额外的空白区.“空白区”通常是指其他元素不能出现且父元素背景可见的区域.——CSS权威指南 我比较喜欢使用“外边距”这个词来解释margin(同理padding可以称之 ...

  7. 【计算机视觉】ARM平台实现人脸检测YSQfastfd

    ARM平台实现于仕琪人脸检测库YSQfastfd 平台要求 ARM32 platform hardware board Ubuntu 16.04 with GTK3 library USB camer ...

  8. 使用Inno Setup Compiler制作安装软件包

    前言 项目开发完成之后,需要程序打包发行,本文使用Inno Setup工具制作安装软件包. 系统环境 系统:win7_x64 工具:Inno Setup Complier 实现步骤 1.下载安装Inn ...

  9. BZOJ3925: [Zjoi2015]地震后的幻想乡【概率期望+状压DP】

    Description 傲娇少女幽香是一个很萌很萌的妹子,而且她非常非常地有爱心,很喜欢为幻想乡的人们做一些自己力所能及的事情来帮助他们. 这不,幻想乡突然发生了地震,所有的道路都崩塌了.现在的首要任 ...

  10. 【WebForm】知识笔记

    一.ashx介绍以及ashx文件与aspx文件之间的区别 ashx是什么文件? .ashx 文件用于写web handler的. .ashx文件与.aspx文件类似,可以通过它来调用HttpHandl ...