<%--
网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
author yeeku.H.lee kongyeeku@163.com
version 1.0
Copyright (C), 2001-2016, yeeku.H.Lee
This program is protected by copyright laws.
Program Name:
Date:
--%>
<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> 表达式语言 - 算术运算符 </title>
<meta name="website" content="http://www.crazyit.org" />
</head>
<body>
<h2>表达式语言 - 算术运算符</h2><hr/>
<table border="1" bgcolor="#aaaadd">
<tr>
<td><b>表达式语言</b></td>
<td><b>计算结果</b></td>
</tr>
<!-- 直接输出常量 -->
<tr>
<td>${1}</td>
<td>${1}</td>
</tr>
<!-- 计算加法 -->
<tr>
<td>${1.2 + 2.3}</td>
<td>${1.2 + 2.3}</td>
</tr>
<!-- 计算加法 -->
<tr>
<td>${1.2E4 + 1.4}</td>
<td>${1.2E4 + 1.4}</td>
</tr>
<!-- 计算减法 -->
<tr>
<td>${-4 - 2}</td>
<td>${-4 - 2}</td>
</tr>
<!-- 计算乘法 -->
<tr>
<td>${21 * 2}</td>
<td>${21 * 2}</td>
</tr>
<!-- 计算除法 -->
<tr>
<td>${3/4}</td>
<td>${3/4}</td>
</tr>
<!-- 计算除法 -->
<tr>
<td>${3 div 4}</td>
<td>${3 div 4}</td>
</tr>
<!-- 计算除法 -->
<tr>
<td>${3/0}</td>
<td>${3/0}</td>
</tr>
<!-- 计算求余 -->
<tr>
<td>${10%4}</td>
<td>${10%4}</td>
</tr>
<!-- 计算求余 -->
<tr>
<td>${10 mod 4}</td>
<td>${10 mod 4}</td>
</tr>
<!-- 计算三目运算符 -->
<tr>
<td>${(1==2) ? 3 : 4}</td>
<td>${(1==2) ? 3 : 4}</td>
</tr>
</table>
</body>
</html>
<%--
网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
author yeeku.H.lee kongyeeku@163.com
version 1.0
Copyright (C), 2001-2016, yeeku.H.Lee
This program is protected by copyright laws.
Program Name:
Date:
--%>
<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> 表达式语言 - 内置对象 </title>
<meta name="website" content="http://www.crazyit.org" />
</head>
<body>
<h2>表达式语言 - 内置对象</h2>
请输入你的名字:
<!-- 通过表单提交请求参数 -->
<form action="implicit-objects.jsp" method="post">
<!-- 通过${param['name']} 获取请求参数 -->
你的名字 = <input type="text" name="name" value="${param['name']}"/>
<input type="submit" value='提交'/>
</form><br/>
<% session.setAttribute("user" , "abc");
// 下面三行代码添加Cookie
Cookie c = new Cookie("name" , "yeeku");
c.setMaxAge(24 * 3600);
response.addCookie(c);
%>
<table border="1" width="660" bgcolor="#aaaadd">
<tr>
<td width="170"><b>功能</b></td>
<td width="200"><b>表达式语言</b></td>
<td width="300"><b>计算结果</b></td>
<tr>
<!-- 使用两种方式获取请求参数值 -->
<td>取得请求参数值</td>
<td>${param.name}</td>
<td>${param.name} </td>
</tr>
<tr>
<td>取得请求参数值</td>
<td>${param["name"]}</td>
<td>${param["name"]} </td>
</tr>
<tr>
<!-- 使用两种方式获取指定请求头信息 -->
<td>取得请求头的值</td>
<td>${header.host}</td>
<td>${header.host}</td>
</tr>
<tr>
<td>取得请求头的值</td>
<td>${header["accept"]}</td>
<td>${header["accept"]}</td>
</tr>
<!-- 获取Web应用的初始化参数值 -->
<tr>
<td>取得初始化参数值</td>
<td>${initParam["author"]}</td>
<td>${initParam["author"]}</td>
</tr>
<!-- 获取session返回的属性值 -->
<tr>
<td>取得session的属性值</td>
<td>${sessionScope["user"]}</td>
<td>${sessionScope["user"]}</td>
</tr>
<!-- 获取指定Cookie的值 -->
<tr>
<td>取得指定Cookie的值</td>
<td>${cookie["name"].value}</td>
<td>${cookie["name"].value}</td>
</tr>
</table>
</body>
</html>
<%--
网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
author yeeku.H.lee kongyeeku@163.com
version 1.0
Copyright (C), 2001-2016, yeeku.H.Lee
This program is protected by copyright laws.
Program Name:
Date:
--%>
<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> 表达式语言 - 逻辑运算符 </title>
<meta name="website" content="http://www.crazyit.org" />
</head>
<body>
<h2>表达式语言 - 逻辑运算符</h2><hr/>
数字之间的比较:
<table border="1" bgcolor="#aaaadd">
<tr>
<td><b>表达式语言</b></td>
<td><b>计算结果</b></td>
</tr>
<!-- 直接比较两个数字 -->
<tr>
<td>${1 < 2}</td>
<td>${1 < 2}</td>
</tr>
<!-- 使用lt比较运算符 -->
<tr>
<td>${1 lt 2}</td>
<td>${1 lt 2}</td>
</tr>
<!-- 使用>比较运算符 -->
<tr>
<td>${1 > (4/2)}</td>
<td>${1 > (4/2)}</td>
</tr>
<!-- 使用gt比较运算符 -->
<tr>
<td>${1 gt (4/2)}</td>
<td>${1 gt (4/2)}</td>
</tr>
<!-- 使用>=比较运算符 -->
<tr>
<td>${4.0 >= 3}</td>
<td>${4.0 >= 3}</td>
</tr>
<!-- 使用ge比较运算符 -->
<tr>
<td>${4.0 ge 3}</td>
<td>${4.0 ge 3}</td>
</tr>
<!-- 使用<=比较运算符 -->
<tr>
<td>${4 <= 3}</td>
<td>${4 <= 3}</td>
</tr>
<!-- 使用le比较运算符 -->
<tr>
<td>${4 le 3}</td>
<td>${4 le 3}</td>
</tr>
<!-- 使用==比较运算符 -->
<tr>
<td>${100.0 == 100}</td>
<td>${100.0 == 100}</td>
</tr>
<!-- 使用eq比较运算符 -->
<tr>
<td>${100.0 eq 100}</td>
<td>${100.0 eq 100}</td>
</tr>
<!-- 使用!=比较运算符 -->
<tr>
<td>${(10*10) != 100}</td>
<td>${(10*10) != 100}</td>
</tr>
<!-- 先执行运算,再进行比较运算,使用ne比较运算符-->
<tr>
<td>${(10*10) ne 100}</td>
<td>${(10*10) ne 100}</td>
</tr>
</table>
字符之间的比较:
<table border="1" bgcolor="#aaaadd">
<tr>
<td><b>表达式语言</b></td>
<td><b>计算结果</b></td>
</tr>
<tr>
<td>${'a' < 'b'}</td>
<td>${'a' < 'b'}</td>
</tr>
<tr>
<td>${'hip' > 'hit'}</td>
<td>${'hip' > 'hit'}</td>
</tr>
<tr>
<td>${'4' > 3}</td>
<td>${'4' > 3}</td>
</tr>
</table>
</body>
</html>
<%--
网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
author yeeku.H.lee kongyeeku@163.com
version 1.0
Copyright (C), 2001-2016, yeeku.H.Lee
This program is protected by copyright laws.
Program Name:
Date:
--%>
<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> 页面配置2 </title>
<meta name="website" content="http://www.crazyit.org" />
</head>
<body>
<h2>页面配置2</h2>
下面是表达式语言输出:<br/>
${1 + 2}<br/>
下面是小脚本输出:<br/>
<%out.println("hello Java");%>
</body>
</html>
<%--
网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
author yeeku.H.lee kongyeeku@163.com
version 1.0
Copyright (C), 2001-2016, yeeku.H.Lee
This program is protected by copyright laws.
Program Name:
Date:
--%>
<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<%@ taglib prefix="crazyit" uri="http://www.crazyit.org/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="website" content="http://www.crazyit.org" />
</head>
<body>
<h2>表达式语言 - 自定义函数</h2><hr/>
请输入一个字符串:
<form action="useFunctions.jsp" method="post">
字符串 = <input type="text" name="name" value="${param['name']}">
<input type="submit" value="提交">
</form>
<table border="1" bgcolor="aaaadd">
<tr>
<td><b>表达式语言</b></td>
<td><b>计算结果</b></td>
<tr>
<tr>
<td>${param["name"]}</td>
<td>${param["name"]} </td>
</tr>
<!-- 使用reverse函数-->
<tr>
<td>${crazyit:reverse(param["name"])}</td>
<td>${crazyit:reverse(param["name"])} </td>
</tr>
<tr>
<td>${crazyit:reverse(crazyit:reverse(param["name"]))}</td>
<td>${crazyit:reverse(crazyit:reverse(param["name"]))} </td>
</tr>
<!-- 使用countChar函数 -->
<tr>
<td>${crazyit:countChar(param["name"])}</td>
<td>${crazyit:countChar(param["name"])} </td>
</tr>
</table>
</body>
</html>
<%--
网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
author yeeku.H.lee kongyeeku@163.com
version 1.0
Copyright (C), 2001-2016, yeeku.H.Lee
This program is protected by copyright laws.
Program Name:
Date:
--%>
<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<%@ page import="java.util.*" %>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>迭代器tag file</title>
<meta name="website" content="http://www.crazyit.org" />
</head>
<body>
<h2>迭代器tag file</h2>
<%
// 创建集合对象,用于测试Tag File所定义的标签
List<String> a = new ArrayList<String>();
a.add("疯狂Java讲义");
a.add("轻量级Java EE企业应用实战");
a.add("疯狂Ajax讲义");
// 将集合对象放入页面范围
request.setAttribute("a" , a);
%>
<h3>使用自定义标签</h3>
<tags:iterator bgColor="#99dd99" cellColor="#9999cc"
title="迭代器标签" bean="a" />
</body>
</html>
<div style="background-color:#dddddd;font-size:10pt">
<font color="blue">Copyright ©right; 2001-2016.
<a href="http://www.crazyit.org">疯狂Java联盟</a></font>
</div>
<div style="background-color:#dddddd;font-size:12pt">
<font color="red">隐式导入的页面头</font>
</div>
<%--
网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
author yeeku.H.lee kongyeeku@163.com
version 1.0
Copyright (C), 2001-2016, yeeku.H.Lee
This program is protected by copyright laws.
Program Name:
Date:
--%>
<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> 页面配置1 </title>
<meta name="website" content="http://www.crazyit.org" />
</head>
<body>
<h2>页面配置1</h2>
下面是表达式语言输出:<br/>
${1 + 2}
</body>
</html>
<?xml version="1.0" encoding="GBK"?>
<!-- 定义生成文件的project根元素,默认的target为空 -->
<project name="web" basedir="." default="">
<!-- 定义三个简单属性 -->
<property name="src" value="src"/>
<property name="classes" value="classes"/>
<!-- 定义一组文件和目录集 -->
<path id="classpath">
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
<pathelement path="${classes}"/>
</path>
<!-- 定义compile target,用于编译Java源文件 -->
<target name="compile" description="编译Java源文件">
<!-- 先删除classes属性所代表的文件夹 -->
<delete dir="${classes}"/>
<!-- 创建classes属性所代表的文件夹 -->
<mkdir dir="${classes}"/>
<copy todir="${classes}">
<fileset dir="${src}">
<exclude name="**/*.java"/>
</fileset>
</copy>
<!-- 编译Java文件,编译后的class文件放到classes属性所代表的文件夹内 -->
<javac destdir="${classes}" debug="true" includeantruntime="yes"
deprecation="false" optimize="false" failonerror="true">
<!-- 指定需要编译的Java文件所在的位置 -->
<src path="${src}"/>
<!-- 指定编译Java文件所需要第三方类库所在的位置 -->
<classpath refid="classpath"/>
</javac>
</target>
</project>
<?xml version="1.0" encoding="GBK"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<!-- 关于JSP的配置信息 -->
<jsp-config>
<jsp-property-group>
<!-- 对哪些文件应用配置 -->
<url-pattern>/noscript/*</url-pattern>
<!-- 忽略表达式语言 -->
<el-ignored>true</el-ignored>
<!-- 页面编码的字符集 -->
<page-encoding>GBK</page-encoding>
<!-- 不允许使用Java脚本 -->
<scripting-invalid>true</scripting-invalid>
<!-- 隐式导入页面头 -->
<include-prelude>/inc/top.jspf</include-prelude>
<!-- 隐式导入页面尾 -->
<include-coda>/inc/bottom.jspf</include-coda>
</jsp-property-group>
<jsp-property-group>
<!-- 对哪些文件应用配置 -->
<url-pattern>*.jsp</url-pattern>
<el-ignored>false</el-ignored>
<!-- 页面编码字符集 -->
<page-encoding>GBK</page-encoding>
<!-- 允许使用Java脚本 -->
<scripting-invalid>false</scripting-invalid>
</jsp-property-group>
<jsp-property-group>
<!-- 对哪些文件应用配置 -->
<url-pattern>/inc/*</url-pattern>
<el-ignored>false</el-ignored>
<!-- 页面编码字符集 -->
<page-encoding>GBK</page-encoding>
<!-- 不允许使用Java脚本 -->
<scripting-invalid>true</scripting-invalid>
</jsp-property-group>
</jsp-config>
<context-param>
<param-name>author</param-name>
<param-value>yeeku</param-value>
</context-param>
</web-app>
<?xml version="1.0" encoding="GBK"?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
web-jsptaglibrary_2_0.xsd" version="2.0">
<tlib-version>1.0</tlib-version>
<short-name>crazyit</short-name>
<!-- 定义该标签库的URI -->
<uri>http://www.crazyit.org/tags</uri>
<!-- 定义第一个函数 -->
<function>
<!-- 定义函数名:reverse -->
<name>reverse</name>
<!-- 定义函数的处理类 -->
<function-class>lee.Functions</function-class>
<!-- 定义函数的实现方法-->
<function-signature>
java.lang.String reverse(java.lang.String)</function-signature>
</function>
<!-- 定义第二个函数: countChar -->
<function>
<!-- 定义函数名:countChar -->
<name>countChar</name>
<!-- 定义函数的处理类 -->
<function-class>lee.Functions</function-class>
<!-- 定义函数的实现方法-->
<function-signature>int countChar(java.lang.String)
</function-signature>
</function>
</taglib>
package lee;
/**
* Description:
* <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
* <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
* <br/>This program is protected by copyright laws.
* <br/>Program Name:
* <br/>Date:
* @author Yeeku.H.Lee kongyeeku@163.com
* @version 1.0
*/
public class Functions
{
// 对字符串进行反转
public static String reverse( String text )
{
return new StringBuffer( text ).reverse().toString();
}
// 统计字符串的个数
public static int countChar( String text )
{
return text.length();
}
}
<%@ tag pageEncoding="GBK" import="java.util.List"%>
<!-- 定义了四个标签属性 -->
<%@ attribute name="bgColor" %>
<%@ attribute name="cellColor" %>
<%@ attribute name="title" %>
<%@ attribute name="bean" %>
<table border="1" bgcolor="${bgColor}">
<tr>
<td><b>${title}</b></td>
</tr>
<%List<String> list = (List<String>)
request.getAttribute("a");
// 遍历输出list集合的元素
for (Object ele : list){%>
<tr>
<td bgcolor="${cellColor}">
<%=ele%>
</td>
</tr>
<%}%>
</table>