zoukankan      html  css  js  c++  java
  • JSTL标准标签库

    现有问题

    • EL主要是用于作用域获取数据,虽然可以做运算判断,但是得到的都是一个结果,做展示.

    • EL不存在流程控制。比如判断.

    • EL对集合只能做单点访问,不能实现遍历操作,比如循环.

    什么是JSTL

    • JSTL:全称Java Server Pages Standard Tag Library

    • JSP标准标签库(JSTL)是JSP标签集合。

    JSTL的作用

    • 可对EL获取到的数据进行逻辑操作。

    • 与EL合作完成数据的展示。

    JSTL使用

    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>taglibs</groupId>
        <artifactId>standard</artifactId>
        <version>1.1.2</version>
    </dependency>
    
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    

    判断、遍历、重写URL

    <%@ page import="java.util.List" %>
    <%@ page import="java.util.ArrayList" %>
    <%@ page import="java.util.Arrays" %>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <html>
    <head>
        <title>jstl</title>
    </head>
    <body>
    
        <%--判断--%>
        <c:if test="${2>1}">
            <h2>2>1</h2>
        </c:if>
        <c:if test="${2<=1}">
            <h2>2<=1</h2>
        </c:if>
    
        <%--多条件判断,像switch--%>
        <%
            request.setAttribute("grade",50);
        %>
        <c:choose>
            <c:when test="${grade >= 80}">
                <h2>优秀</h2>
            </c:when>
            <c:when test="${grade >= 60 && grade <80}">
                <h2>良好</h2>
            </c:when>
            <c:otherwise>
                <h2>不及格</h2>
            </c:otherwise>
    
        </c:choose>
    
        <hr/>
    
    
        <%--遍历--%>
        <%
            List<String> list = Arrays.asList("A","B","C","D");
            request.setAttribute("list", list);
        %>
        <c:forEach items="${requestScope.list}" var="i" varStatus="status">
            <h2>${i}&nbsp; ${status.index}&nbsp; ${status.count}&nbsp; ${status.count%2==0}&nbsp; ${status.first}&nbsp; ${status.last}&nbsp;</h2>
        </c:forEach>
    
        <hr/>
    
        <%--重写URL--%>
        <%
            String  newUrl = response.encodeRedirectURL(request.getContextPath()+"/index.jsp");
        %>
        <%=newUrl%>
    
        <a href="<%=response.encodeRedirectURL(request.getContextPath()+"/index.jsp")%>">重写URL跳转</a>
        <a href="<c:url context='${pageContext.request.contextPath}' value='/index.jsp'/>">重写URL跳转</a>
    
    </body>
    </html>
    
    • 禁用cookie才会url重写

    --------------- 我每一次回头,都感觉自己不够努力,所以我不再回头。 ---------------
  • 相关阅读:
    Java基础教程
    一个RDBMS左连接SQL执行计划解析
    hive时间日期函数及典型场景应用
    ETL数据采集方法
    数据仓库保存历史数据方法之拉链表
    NAS服务器局域网内IPad、手机、电视盒子等联网播放
    转:主流数据恢复软件——EasyRecovery/Ashampoo Undeleter/Wise Data Recovery/Recuva/Undelete 360
    [转]office2010一直卡在“正在受保护的视图中打开”
    [转]PROE传动链条的装配教程
    linux下svn定时更新项目
  • 原文地址:https://www.cnblogs.com/zjw-blog/p/13929594.html
Copyright © 2011-2022 走看看