标签:style blog http io color ar java sp for
语法:${运算表达式},EL表达式支持如下运算符
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 <%@page import="com.yyz.User"%> 3 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 4 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 5 <html> 6 <head> 7 <title>el表达式运算符</title> 8 </head> 9 <body> 10 ${365*24 } 11 <br> 12 ${user==null } 13 <br/> 14 <!-- empty运算符:检查对象是否为null或“空”. --> 15 <% 16 List list = null; 17 //List list = new ArrayList(); 18 //list.add("a"); 19 //list.add("b"); 20 request.setAttribute("list",list); 21 %> 22 <!-- list为null或者集合中没有存放元素,empty返回都为true --> 23 <c:if test="${!empty(list)}"> 24 <c:forEach var="str" items="${list}"> 25 ${str } 26 </c:forEach> 27 </c:if> 28 <c:if test="${empty(list)}"> 29 对不起,没有您想看的数据 30 </c:if> 31 32 <br/> 33 <!-- 二元表达式:${user!=null?user.name : “”} . --> 34 <% 35 session.setAttribute("user", new User("ccccc")); 36 %> 37 ${user==null?"对不起,您没有登录":user.username } 38 <br/> 39 <!-- 数据回显 --> 40 <% 41 User user = new User(); 42 user.setGender("male"); 43 request.setAttribute("user", user); 44 %> 45 <input type="radio" value="male" name="gender" ${user.gender=="male"?"checked":"" }>男 46 <input type="radio" value="female" name="gender" ${user.gender==‘female‘?‘checked‘:‘‘ }>女 47 <br> 48 </body> 49 </html>
标签:style blog http io color ar java sp for
原文地址:http://www.cnblogs.com/yyz666/p/4083573.html