您的位置:首页 > 其它

EL表达式

2015-06-07 00:00 148 查看
摘要: ${}

<%@ page language="java" import="java.util.*,model.*" isELIgnored="false" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>

<body>
<h2>EL表达式可以出现在HTML,JSP标签中,但是不能使用在JSP的表达式,代码片段,声明中!</h2>
<hr>
<h3>EL表达式中常量的使用</h3>
${100}<br/>
${250.259 }<br>
${'liss' }<br>
${true }<br>
${false }<br>
${5>9 }<br>
${null }<br>
${'null' }<br>
<hr>

<h3>EL表达式中算术运算符</h3>
1+1=${1+1 }<br>
10/5=${10/5 }<br>
10%5=${10%5 }=${10 mod 5 }<br>
<hr>

<h3>EL表达式中关系运算符</h3>
${5>4?"zhangsan":"lisi" }<br>
<hr>

<h3>EL表达式中empty</h3>
${empty null }<br>
<hr>

<h3>EL表达式中11个隐式对象</h3>
<%
pageContext.setAttribute("msg", "我是pageContext中的数据");
request.setAttribute("msg", "我是request中的数据");
session.setAttribute("msg", "我是session中的数据");
application.setAttribute("msg", "我是application中的数据");
%>
${msg }
<hr>

<h3>EL表达式中的存取器</h3>
<%
Student stu1=new Student(1001,"zhangsan");
Student stu2=new Student(1002,"lisi");
request.setAttribute("stu1", stu1);
request.setAttribute("stu2", stu2);

List<String> list1=new ArrayList<String>();
list1.add("apple");
list1.add("banana");
list1.add("orange");
request.setAttribute("list1", list1);

List<Student> list2=new ArrayList<Student>();
list2.add(stu1);
list2.add(stu2);
request.setAttribute("list2", list2);
%>

<!-- 自身机制 -->
${stu1.id } ${stu1.name}<br>
${stu2.id } ${stu2.name}<br>

${stu1['id'] } ${stu1['name']}<br>
${stu2['id'] } ${stu2['name']}<br>

${list1[0] } ${list1[1] } ${list1[2] } <br>

${list2[0].id } ${list2[0].name }<br>
${list2[1].id } ${list2[1].name }<br>
<hr>

<h3>EL表达式中的11个隐式对象</h3>
pageContext--->${pageContext.request.contextPath }<br>
param--->${param.name }<br>
paramValues--->${paramValues.name[1] }<br>

pageScope-->${pageScope.msg }<!-- 就相当于pageContext.getAttribute("msg"); --><br>
requestScope-->${requestScope.msg }<br>
sessionScope-->${sessionScope.msg }<br>
applicationScope-->${applicationScope.msg }<br>
header-->${header.host }<br>
<hr>

<h3>在html标签中也能用</h3>
<input type="text" name="name" value="${header.host }">
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: