EL表达式学习笔记(JSTL)

<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>



  
    
    
    My JSP 'JSTL_test.jsp' starting page
    
	
	
	    
	
	
	

  
  
  
    

测试EL表达式


  • 普通字符串
  • hello(jsp脚本):<%request.getAttribute("hello");%>
    hello(EL表达式使用$和{}):${hello}
    hello(el表达式,el的隐含对象:pageScope,requestScope,sessionScope,applicationScope
    如果没有指定scope,则它的搜索顺序为 pageScope ----> applicationScope):${requestScope.hello }
  • 结构
  • 姓名:${user.userName}(与对象的方法(get)相关)
    年龄:${user.age }
    所属组:${user.group.name }
  • 输出map
  • mapvalue.key1:${mapvalue.key1 }
    mapvalue.key2:${mapvalue.key2 }
  • 数组输出,采用[]和下标
  • atrarray[2]:${astarray[1] }
  • 输出对象数组
  • userarray[3].username:${users[2].username }
  • 输出list,采用[]和下标
  • userlist[5].username:${userlist[4].username }
  • el表达式对运算符的支持
  • 1 + 2 = ${1+2 }
    10 / 5 = ${10/5 }
    10 / 5 = ${10 div 5 }
    10 % 3 = ${10%3 }
    10 % 3 = ${10 mod 3 }
    <-- == eq != ne < lt > gt <= le >= ge && and || or ! not / div % mod -->
  • 测试empty
  • value1:${not empty value1 }
    value2:${empty value1 }
    value3:${empty value1 }
    value4:${empty value1 }

     

    转载于:https://www.cnblogs.com/hbiao68/archive/2011/10/19/2218244.html

    你可能感兴趣的:(java)