JDBC+Servlet+JSP整合開發之29-JSP表達式語言(EL)

–EL 簡介
–EL的應用場合
–EL 的基本語法
–EL中的算術運算符
–EL中的關係運算符
–EL中的邏輯運算符
------------------------------START-----------------------------------
? EL簡介
–是一種簡單的表達式語言
–能夠訪問變量、JavaBean的屬性、集合和數組
–能夠進行關係、邏輯和算術運算
–能夠訪問內建對象
? EL的應用場合
–在標籤的屬性值中使用:
? <some:tag value=“${expr}” />
ELJSP.jsp
image
測試:
image
–作爲判斷條件:
<c:if test=“${!empty param.username}”>

</c:if>
image
測試:
image
image
測試:
image
–在JSP頁面中直接使用:
? One value is ${bean1.a} and another is
${bean2.a.c}
image
測試:
image
看下在JAVABean中如何實現哈~
User.java
image
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>
測試:
image
? EL 的基本語法
?訪問變量

–${變量名稱}
?訪問maps、lists、arrays ,使用“[]”
–customerList[0]
image
測試:
image
?訪問 JavaBean 的屬性,使用“.”,並且可以嵌套
–user.name.firstName
Customer.java
image
Name.java
image
ELJSP.jsp
image
測試:
image 
? EL中的算術運算符
– "+"
– "-"
– "*"
– "/"
– "%"
? EL中的關係運算符
–“== ” or “eq”
–“!=“ or “ne”
–“<“ or “lt”
–“>” or “gt”
–“<=“ or “le”
–“>=“ or “ge”
? EL中的邏輯運算符
–“&&” and “and”
–“||” and “or”
–“!” and “not”
image
 image
測試:
 image
------------------------------------END--------------------------------
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章