JSP学习----之表达式语言内置对象

1,EL表达式语言内置对象
No内置对象描述                                  
1pageContext代表该页面的pageContext对象,与JSP的pageContext内置对象相同
2pageScope用于获取page范围的属性值
3requestScope用于获取request范围的属性值
4sessionScope用于获取session范围的属性值
5applicationScope用于获取application范围的属性值
6param用于获取请求的参数值
7paramValues用于获取请求的参数值,与param的区别在于,该对象用于获取属性值为数组的属值
8header用于获取请求头的属性值
9headerValues用于获取请求头的属性值,与header的区别在于,该对象用于获取属性值为数组的属性值
10initParam用于获取请求Web应用的初始化参数
11cookie用于获取指定的Cookie值
<!-- 基本使用 -->
	<%
		request.setAttribute("info","www.baidu.com");
		if(request.getAttribute("info")!= null){
	%>
	<h3><%=request.getAttribute("info") %></h3>
	<%
		} 
	%>
	<!-- page,request,response,application 四个对象的值都可以获取 -->
	<h3>${info}</h3>
		
<!-- 属性范围 -->		
	<%
		pageContext.setAttribute("info","page属性范围");
	request.setAttribute("info","request属性范围");
	session.setAttribute("info","session属性范围");
	application.setAttribute("info","application 属性范围");
	%>
	<h3>page 属性内容:${ pageScope.info}</h3>
	<h3>request 属性内容:${ requestScope.info}</h3>
	<h3>session 属性内容:${ sessionScope.info}</h3>
	<h3>application 属性内容:${ applicationScope.info}</h3>
	
<!-- 集合操作 -->		
	
	<%
		List all = new ArrayList();
		all.add("李丹");
		all.add("www.baidu.com");
		all.add("www.baidu.com");
		all.add("www.baidu.com");
		request.setAttribute("allinfo",all);
		
		Map map = new HashMap();
		map.put("id","李丹");
		map.put("site","www.baidu.com");
		map.put("email","2001@qq.com");
		request.setAttribute("mapinfo",map);
		
		
	%>
	<h3>第一个元素:${allinfo[0] } </h3>
	<h3>第二个元素:${allinfo[1] } </h3>
	<h3>第三个元素:${allinfo[2] } </h3>
	<h3>第四个元素:${allinfo[3] } </h3>
	<br/><br/><br/>
	
	<h3>第一个元素:${mapinfo["id"] } </h3>
	<h3>第二个元素:${mapinfo.site } </h3>
	<h3>第一个元素:${mapinfo["email"] } </h3>
2,EL表达式的运算符
<%-------------------------EL表达式  运算符----------------------- --%>
	<h3>${20+30} </h3>
	<h3>${20-30} </h3>
	<h3>${20*30} </h3>
	<h3>${20/30} </h3>
	<h3>${20%30} </h3>
	<%
		pageContext.setAttribute("a",20);
		pageContext.setAttribute("b",30);
		pageContext.setAttribute("c",3);
		
		pageContext.setAttribute("flag1",true);
		pageContext.setAttribute("flag2",false);
		
	%>
		<h3>加 :${a+b} </h3>
		<h3>减:${a-b} </h3>
		<h3>乘:${a*b} </h3>
		<h3>除:${a/b} </h3>
		<h3>取模:${a%b} </h3>
		
		<h3>等于 :    ${a==b}  和和和和和  ${a eq b} </h3> 
        <h3>不等于:   ${a!=b}  和和和和和  ${a ne b} </h3>
        <h3>小于:     ${a<b}   和和和和和  ${a lt b} </h3>
        <h3>大于:     ${a>b}   和和和和和  ${a gt b} </h3>
        <h3>小于等于: ${a<=b}  和和和和和  ${a le b} </h3>
        <h3>大于等于: ${a>=b}  和和和和和  ${a ge b} </h3>
        
        <h3>与操作: ${flag1 && flag2}   和和和和和  ${flag1 and flag2} </h3>
        <h3>或操作: ${flag1 || flag2}  和和和和和  ${flag1 or flag2} </h3>
        <h3>非操作: ${!flag1}  和和和和和  ${not flag1} </h3>
        
        
        <h3>是否为空:    ${empty a} </h3>
        <h3> 三目运算   ${a>b?"大于":"小于"} </h3>
        <h3> 括号运算符   ${c*(a+b)} </h3>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值