纯属资料的记录,供查询之用。
详细内容请参考http://java.sun.com/products/jsp/docs.html
1. JSP: Java Server Pages,建立在Java Servlet模型之上的表达层技术,由J2EE服务器的JSP引擎编译执行。
2. J2ee服务器处理JSP请求的三个阶段:
(1)translation phase:将JSP翻译成servlet代码;
(2)compilation phase:编译servlet代码为class文件;
(3)request phase:接到request侯,执行相应的class文件,展示生成的页面。
3. JSP的三种元素:
3.1 JSP的脚本元素:
(1)脚本格式(Scriptlet)
语法: <% code fragment %> 或者 <jsp:scriptlet> code fragment </jsp:scriptlet>
例子: <% out.println("Hello Guy!"); %>
(2)表达式格式(Expression)
语法: <%= expression %> 或者 <jsp:expression> expression </jsp:expression>
例子: <% int i=5; %>
html....
<%= i %>
(3)声明格式(Declaration)
语法: <%! declaration; [ declaration; ]+ ... %> 或者 <jsp:declaration> code fragment [ declaration; ]+ ... </jsp:declaration>
例子: <%! String name = "tom";
String returnID(){
return name;
}
%>
<%
String user=returnID();
out.println("User is:"+user);
%>
3.2 JSP的指令元素:
(1)Page指令: 对JSP文件的全局属性进行定义。
语法:
<%@ page
[ language="java" ]
[ extends="package.class" ]
[ import="{package.class | package.*}, ..." ]
[ session="true|false" ]
[ buffer="none|8kb|sizekb" ]
[ autoFlush="true|false" ]
[ isThreadSafe="true|false" ]
[ info="text" ]
[ errorPage="relativeURL" ]
[ contentType="mimeType [ ; charset=characterSet ]" |
"text/html ; charset=ISO-8859-1" ]
[ isErrorPage="true|false" ]
[ pageEncoding="characterSet | ISO-8859-1" ]
[ isELIgnored="true|false"]
%>
或者:
<jsp:directive.page pageDirectiveAttrList />
例子:
<%@ page import="java.util.Date, java.lang.*" %>
<%@ page buffer="5kb" autoFlush="false" %>
<jsp:directive.page errorPage="error.jsp" />
(2)Include指令:用来引用外部文件,比如将导航栏系在一个单独的文件中,然后引入到其他文件。
语法: <%@ include file="relativeURL" %> 或者 <jsp:directive.include file="relativeURL" />
例子:
include.jsp:
<html>
<head><title>An Include Test</title></head>
<body bgcolor="white">
<font color="blue">
The current date and time are
<%@ include file="date.jsp" %>
</font>
</body>
</html>
date.jsp:
<%@ page import="java.util.*" %>
<%= new Date()%>
Displays in the page:
The current date and time are
Sun Mar 21 13:53:26 CST 2010
注意:通过Include指令合并的两个或多个页面是在容器翻译阶段发生的。对于上例,容器先原封不动地将date.jsp的内容插入到include.jsp中,然后翻译,编译,接到请求再执行。
(3)Taglib指令: 用来映入标签(包括自定义的),或标签库。后续文章会详细介绍。
语法:<%@ taglib {uri="URI" | tagdir="/WEB-INF/tags[/subdir]+"} prefix="tagPrefix" %>
例子:<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix:"sql" %>
-------------------------------------下面的指令是自定义tag时候用的,不予详述--------------------------------------------------------
(4)Tag指令:用来声明自定义tag的properties。
(5)Attribute指令: 用来声明一个tag的属性,仅仅用在tag文件中,比如当你自定义一个tag的时候就会用到。
(6)Variable指令:在自定义标签中,声明一个变量,给其赋值,使用时可直接用EL表达式展示。
3.3 常用的JSP的动作元素:
(1)<jsp:useBean>
(2)<jsp:setProperty>
(3)<jsp:getProperty>
(4)<jsp:include>
(5)<jsp:forward>
(6)<jsp:param>
(7)<jsp:plugin>
(8)<jsp:paramas>
(9)<jsp:fallback>
可参考:
http://www.blogjava.net/wujun/archive/2009/03/28/37521.html
http://bye.iteye.com/blog/202646