一.EL(Expression Language)标签:例:${sessionScope.user.sex}意思是在session这个空间里将user对象的sex属性值性别取出来输出到浏览器。
二.EL运算符之 .和[ ]:上面的EL表达式也可以这样写: $ {sessionScope.user[sex]};
三.有的时候非[ ]不可,比如当你的sex属性命名时是user.sex这个样子的那么你就必须这样写:
$ {sessionScope.user[“user.sex”]}; 如果EL表达式中涉及到变量时要用[ ],例如:pageContext.setAttribute(“var”,“user1”);//在当前页面的域空间里设置了一个值当这个var的值是个变量。${sessiScope[pageScope.var].username};等同于 ${sessionScope[param[user].username};
四.EL中提供了自动转变类型的功能,并可以做算术运算。${param.id+10} 输出结构20.EL输出常数的时候必须加上 " " .
五.EL中的隐含对象:pageScope. requestScope. sessionScope. applicationScope.取得范围的属性值。
cookie EL中只能取得cookie的属性值 ${cookie.userKey}.
param和paramValues等同于getParameter和getParameterValues.
| ${pageContext.request.queryString}| 取得请求的参数字符串 |
|
p
a
g
e
C
o
n
t
e
x
t
.
r
e
q
u
e
x
t
.
r
e
q
u
e
s
t
U
R
L
(
)
∣
取
得
请
求
的
U
R
L
,
但
不
包
括
请
求
的
参
数
字
符
串
,
即
s
e
r
v
l
e
t
的
H
t
t
p
地
址
∣
∣
{pageContext.requext.requestURL()}|取得请求的URL,但不包括请求的参数字符串,即servlet的Http地址| |
pageContext.requext.requestURL()∣取得请求的URL,但不包括请求的参数字符串,即servlet的Http地址∣∣ {pageContext.request.contextpath()} |服务的webapplication的名称 |
|$ {pageContext.request.method} |取得http的方法(GET POST)|
Empty 判断是否为空。
JAVA中提供了一个默认的实现类SimpleTagSupport来实现自定义标签,我们只需要继承此类即可。
自定义标签开发的步骤:
①:编写标签功能的JAVA类(标签处理器) ②:编写标签库描述文件(.tld) ③:jsp页面中导入和使用自定义的标签。
Pulic class MyTag extends SimpleTagSupport{
public void doTage(){ //这个方法相当于main()方法
getJspContext().getOut().println(“Hello tage”);
}
}
写.tld文件:去tomcat中的webinf下的jsp.tld文件中拷贝头部和tag属性。
< description>A tag library exercising SimpleTag handlers.< /description>
< tlib-version>1.0< /tlib-version>
< short-name>SimpleTagLibrary< /short-name>
< uri>http://mytag.com/core< /uri>
< tag>
< description>Repeats the body of the tag ‘num’ times< /description>
< name>MyTag< /name>
< tag-class>jsp2.examples.simpletag.RepeatSimpleTag< tag-class>//标签处理器的包全名
< body-content>empty< /body-content>
< attribute>
< name>map< /name>
< required>true< /required>
< rtexprvalue>true< /rtexprvalue> //标签可以接受表达式
< /attribute>
< /tag>
< /taglib>
//在JSP中导入自定义标签:< %@ taglib prefix=“mt” uri=“http://mytag.com/core” %>