码迷,mamicode.com
首页 > 其他好文 > 详细

el表达式

时间:2016-11-22 09:46:50      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:htm   base   his   image   author   link   pat   sep   字符   

技术分享
<%@page import="cn.bdqn.bean.News"%>
<%@ 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>
    
    <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>
<%--  el表达式 :(Expression  Language) 目的:就是为了简化我们的表达式
      语法结构:${表达式}     着重点 在于数据的显示!
      表达式必须被放在某个作用于中!
                               
                                作用域:
   page            pageScope
   request         requestScope
   session         sessionScope
   application     applicationScope
    
    el表达式 默认的作用域 搜索顺序  page  -->  request -->session -->application
    我们只需要把数据放入 指定的作用域,那么我们就可以从指定的作用域中取到数据!
    我们把值放进了page作用域中,其他的作用域拿不到值!
     ${aName}  不加作用域   按照 默认的作用域 搜索顺序
      ${pageScope.pName}  值从page作用域中 查询
  --%>
  <body>
  
  
  <%
    //把单个字符串放入作用域
     pageContext.setAttribute("pName", "小白");
     request.setAttribute("rName", "小黑");
     session.setAttribute("sName", "小红");
     application.setAttribute("aName", "小兰");
    //把集合放入作用域
    ArrayList<String> lists=new ArrayList();
    lists.add("小白兔");
    lists.add("白又白");  
    request.setAttribute("list", lists);
    //把对象放入作用域
    News news=new News();
    news.setAuthor("admin");
    news.setCreateDate(new Date());
    session.setAttribute("news", news);
  %>     
  ${5.02}<br/>
  ${5>2}<br/>
  ${(1==2)?"你好":"不好"}<br/>
  
page作用域:  ${pageScope.pName}<br/>
request作用域:  ${requestScope.rName} <br/>
session作用域:  ${sName}<br/>
application作用域: ${aName}<br/>
  
 拿到集合中的第一个元素:${list[0]}<br/>
 获取新闻的创建时间(使用最多):${news.createDate} <br/>
 获取新闻的创建时间:${news.getCreateDate()} <br/>
 获取新闻的创建时间:${news["author"]} <br/>
  
  </body>
</html>
el表达式

 

el表达式

标签:htm   base   his   image   author   link   pat   sep   字符   

原文地址:http://www.cnblogs.com/999-/p/6087858.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!