【javaweb笔记】10、EL表达式语法,点操作符,括号操作符,EL运算,隐式对象

EL :为了消除jsp中的Java代码

语法:
${EL表达式}
a.EL不需要导包
b.在el中调用属性,其实是调用的getXxx()方法

${范围.对象.属性.属性的属性 }

操作符:操作:属性,不是对象
. : 使用方便
[] : 如果是常量属性,需要使用双引号/单引号 引起来;比点操作符更加强大


[]强大之处:
a.可以容纳一些 特殊符号 (.  ?   -)
b.[]可以容纳 变量属性 (可以动态赋值)
String x = "a";
${requestScope.a}等价于${requestScope["a"]}等价于${${requestScope[x]}

c.可以处理数组
${requestScope.arr[0] }

普通对象、map中的变量


通过EL获取JSP  九大内置对象
${pageContext }
${pageContext.request }
${pageContext.sessoin }

el.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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>			
		
		
		
		----------EL---点操作符-------------------<br/>
		学生对象:${requestScope.student}<br/>
		学号:${requestScope.student.sno}<br/>
		
		===姓名:${requestScope.student.sname}<br/>
		
		学校地址:${requestScope.student.address.schoolAddress}<br/>
		家庭地址:${requestScope.student.address.homeAddress}<br/>
		he-llo的值:${requestScope.he-llo }
		
		<br/>	----------EL------中括号操作符----------------<br/>
		学生对象:${requestScope.student}<br/>
		学号344:${requestScope.student['sno']}<br/>
		===姓名:${requestScope.student[x]}<br/>
		
		学校地址:${requestScope.student["address"]["schoolAddress"]  }<br/>
		家庭地址xx:${requestScope.student["address"]["homeAddress"]  }<br/>
		he-llo的值:${requestScope["he-llo"] }
		
		处理数组:
		<br/>
		x1xx:${requestScope.arr[0] }、
		xx2x:${requestScope.arr[1] }、
		xx3x:${requestScope.arr[2] }、
		
		===<br/>
		${requestScope.countries.cn }、
		${requestScope.countries["us"] }



	

<br/>								
<br/>								
<br/>								
		<form action="UploadServet" method="post"  enctype="multipart/form-data">
			学号:<input name="sno" /><br/>
			姓名:<input name="sname" /><br/>
			上传照片: <input type="file"  name="spicture"/>
			<br/>
			<input type="submit" value="注册"/>
		</form>
		<a href="DownloadServlet?filename=图片.png">图片</a>
		
</body>
</html>

猜你喜欢

转载自blog.csdn.net/kuaileky/article/details/86724310
今日推荐