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>
相关文章推荐
- 核心标签库-------------------二
- JSTL 国际化标签
- intellij idea maven dependency自动补全
- jersey-spring,jersey集成spring
- LeetCode Contains Duplicate II
- 随记一linux基础命令操作
- SecViz
- HDU 4971 - A simple brute force problem【最大权闭合图】
- 两段简单的JS代码防止SQL注入
- Oracle之constraint/index/view/sequence/grant
- 用CANVAS画个时钟
- Latex 主题设置
- centos下挂载NTFS移动硬盘
- 为何需要总结
- 文章标题
- 读书笔记:机器学习实战(1)——章2的knn代码和个人改进与注释
- DICOM:Ubuntu14环境下安装dcm4chee+oviyam2.1
- 正则表达式
- OK6410开发板在make uboot时报错
- 原子性(atomicity)