javaWEB-动态网页之el表达式
来源:互联网 发布:返利机器人软件收费 编辑:程序博客网 时间:2024/05/22 01:38
<%@ page language="java" import="java.util.*" 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 'el.jsp' starting page</title> </head> <body> <%-- EL 表达式 就是一个公式 , 该公式里面可以写任何式子代码 EL 表达式里面有几个内置对象 pageContext pageScope requestScope sessionScope applicationScope param paramValues initParam Cookie header --%> <% pageContext.setAttribute("info","Page 范围 ! "); request.setAttribute("info","Request 范围 ! "); session.setAttribute("info","Session 范围 ! "); application.setAttribute("info","Application 范围 ! "); ArrayList list = new ArrayList(); pageContext.setAttribute("list",list); %> ${ 1 + 1} ${ 1==2 ? true : false} <br/> <!-- el 表达式 取 返回中的值 , 从小到大依次取值 . 取第一个出现的值 --> 范围取值: ${ pageScope.info } , ${ requestScope.info } , ${ sessionScope.info } , ${ applicationScope.info } , ${ info } <br/> <!-- 判断对象是否为 空集合 使用 empty 空对象 使用 == null --> ${ list == null } ${ empty list } <br/> <!-- 获取 地址栏传递过来的参数 --> ${ param.test } ${ paramValues.n[2] } <!-- 获取 web.xml 项目初始化参数 --> ${ initParam.name } <br/> <!-- 获取头信息 --> ${ header.host } </body></html>