• jstl与el学习笔记


    EL(Expression Language,表达式语言):

    Jsp2.0后不仅可以在jstl中应用而且可以直接在jsp中应用,常见写法${expression}

    长于jstl标签的test属性一起构成条件判断,如:

    <c:if test=${param.age>100}>

    年龄大于100

    </c:if>

    param是el的内置对象,表请求参数

    paramValues也是内置对象,表情求参数数组,使用:${paramValues[2]}等等

    JSTL(JSP Standard Taglib Language,jsp标准标签库)

    有5个组成部分:

    core:c

    format:fmt

    functions:fn

    xml:xml

    sql:sql

    使用举例:

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        
        <title>My JSP 'choose.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>
        <%
        	String[] namesStr = new String[]{"n1", "n2", "n3", "n4"};
        	Map<String, String> dictMap = new HashMap<String, String>();
        	dictMap.put("k1", "v1");
        	dictMap.put("k2", "v2");
        	
        	pageContext.setAttribute("names", namesStr);
        	pageContext.setAttribute("dict", dictMap);
        %>
        
        <c:forEach var="name" items="${names}" begin="1" end="2" step="1" varStatus="i">
        	名称:${name},序号:${i.index },已经输出:${i.count },是否是第一个元素:${i.first },最后?:${i.last }<br/> 
        </c:forEach>
        <br/>
        <br/>
        <c:forEach var="name" items="${dict}">
        	键:${name.key},值:${name.value }。<br/>
        </c:forEach>
      </body>
    </html>
    
     
    结果:
    名称:n2,序号:1,已经输出:1,是否是第一个元素:true,最后?:false
    名称:n3,序号:2,已经输出:2,是否是第一个元素:false,最后?:true


    键:k1,值:v1。
    键:k2,值:v2。
  • 相关阅读:
    Python采用struct处理二进制
    OVS处理upcall流程分析
    mybatis在CRUD
    leetcode先刷_Valid Sudoku
    [TS] Implement a doubly linked list in TypeScript
    [TS] Implement a singly linked list in TypeScript
    [Python] The get() method on Python dicts and its "default" arg
    [Javascript AST] 4. Continue: Report ESLint error
    [RxJS] Learn How To Use RxJS 5.5 Beta 2
    [NPM] Update published npm packages using np
  • 原文地址:https://www.cnblogs.com/nysanier/p/2190575.html
Copyright © 2020-2023  润新知