JDBC+Servlet+JSP整合开发之29-JSP表达式语言(EL)

–EL 简介
–EL的应用场合
–EL 的基本语法
–EL中的算术运算符
–EL中的关系运算符
–EL中的逻辑运算符
------------------------------START-----------------------------------
? EL简介
–是一种简单的表达式语言
–可以访问变量、JavaBean的属性、集合和数组
–可以进行关系、逻辑和算术运算
–可以访问内建对象
? EL的应用场合
–在标签的属性值中使用:
? <some:tag value=“${expr}” />
ELJSP.jsp
p_w_picpath
测试:
p_w_picpath
–做为判断条件:
<c:if test=“${!empty param.username}”>

</c:if>
p_w_picpath
测试:
p_w_picpath
p_w_picpath
测试:
p_w_picpath
–在JSP页面中直接使用:
? One value is ${bean1.a} and another is
${bean2.a.c}
p_w_picpath
测试:
p_w_picpath
看下在JAVABean中如何实现哈~
User.java
p_w_picpath
ELJSP.jsp
<%@ page language= "java" import= "java.util.*,com.michael.bean.*" pageEncoding= "gbk"%>    
<%@ taglib uri= "http://java.sun.com/jsp/jstl/core" prefix="c" %>    
<%    
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 'ELJSP.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>    
        <%request.setAttribute("URL","http://redking.blog.51cto.com"); %>    
        <c:out value="${URL }"></c:out><br>    
        <hr>    
        URL:<input type="text" value="${URL }"><br>    
        <hr>    
        <%request.setAttribute("username","michael"); %>    
        <c:if test="${username=='admin'}">    
                <input type="button" value="delete"/>    
        </c:if>    
        <c:if test="${username!='admin'}">    
                <input type="button" value="delete" disabled="disabled"/>    
        </c:if>    
        <br><hr>    
        UserName:${username }<br>    
        <hr>    
        <%    
        User u = new User();    
        u.setId(1);    
        u.setName("珊珊");    
        request.setAttribute("u",u);    
         %>    
         ID:${u.id }<br/>    
         Name:${u.name }<br/>    
    </body>    
</html>
测试:
p_w_picpath
? EL 的基本语法
?访问变量

–${变量名称}
?访问maps、lists、arrays ,使用“[]”
–customerList[0]
p_w_picpath
测试:
p_w_picpath
?访问 JavaBean 的属性,使用“.”,而且能够嵌套
–user.name.firstName
Customer.java
p_w_picpath
Name.java
p_w_picpath
ELJSP.jsp
p_w_picpath
测试:
p_w_picpath 
? EL中的算术运算符
– "+"
– "-"
– "*"
– "/"
– "%"
? EL中的关系运算符
–“== ” or “eq”
–“!=“ or “ne”
–“<“ or “lt”
–“>” or “gt”
–“<=“ or “le”
–“>=“ or “ge”
? EL中的逻辑运算符
–“&&” and “and”
–“||” and “or”
–“!” and “not”
p_w_picpath
  p_w_picpath
测试:
  p_w_picpath
------------------------------------END--------------------------------
相关文章
相关标签/搜索