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重写

    --------------- 我每一次回头,都感觉自己不够努力,所以我不再回头。 ---------------
  • 相关阅读:
    Django Admin 管理工具
    老男孩培训机构老师的博客
    pycharm版本选择并安装
    Linux命令-自动挂载文件/etc/fstab功能详解
    django urls路由匹配分发
    django templates模板
    Django models模型
    django views视图函数
    JDK与JRE、JVM三者间的关系及JDK的安装部署
    django 第一个项目测试
  • 原文地址:https://www.cnblogs.com/zjw-blog/p/13929594.html
Copyright © 2011-2022 走看看