zoukankan      html  css  js  c++  java
  • jsp-EL-JSTL标签库

    jsp el 表达式输出
    表达式语言,必须在jsp页面中使用

    ${msg}
    ${st.name} 相当于 st.getName()
    page pageScope
    request requestScope
    session sessionScope
    application applicationScope

    ${2*3}
    <hr>
    <%
    pageContext.setAttribute("age",18);
    request.setAttribute("age",28);
    session.setAttribute("age",38);
    application.setAttribute("age",48);
    %>
    <hr>
    ${age}
    <br>->pageScope -> requestScope -> sessionScope -> applicationScope <br>
    ${sessionScope.age}

    pageContext.setAttribute("sts",new MyDbUtil().query("select * from student"));
    pageContext.setAttribute("sss",new MyDbUtil().query("student","*","where 1=1","order by id desc","limit 20"));
    <hr>
    姓名:${sts[0].name},成绩:${sts[0].score}分,出生年月:<fmt:formatDate value="${sts[0].birthday}" pattern="yyyy年MM月dd日"/>
    <hr>
    ${sss.size()}<br>
    姓名:${sss[0].name}---<fmt:formatDate value="${sss[0].birthday}" pattern="yy-MM-dd"/>


    ${param.id} 相当于 <%=request.getParameter("id");%>


    特别常用的EL

    取得客户端的IP并显示 xxx.xxx.xxx.xxx
    ${pageContext.request.remoteAddr}

    取得项目的路径 /web07
    ${pageContext.request.contextPath}

    jsp jstl JSP标准标签库
    jsp standard tag lib

    引入标签库jar文件
    javax.servlet.jsp.jstl.jar
    jstl-impl.jar

    必须在jsp页面上编写标签
    核心 必须掌握
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <c:forEach begin="1" end="10" step="1" var="c">
    <c:if test="${(11-c)%2==0}">
    <h3 style="background-color: #f00;">${11-c}</h3>
    </c:if>
    <c:if test="${(11-c)%2!=0}">
    <h3 style="background-color: #ff0;">${11-c}</h3>
    </c:if>

    </c:forEach>
    <hr>
    <c:forEach begin="1" end="10" step="1" var="i">
    <h3><fmt:formatNumber minIntegerDigits="3" pattern="0.000" value="${i}"/></h3>
    </c:forEach>

    <c:forEach begin="1" end="10" step="1" var="c">
    <c:if test="${(11-c)%2==0}"><c:set var="cc" value="red"/> </c:if>
    <c:if test="${(11-c)%2!=0}"><c:set var="cc" value="blue"/> </c:if>
    <h3 style="background-color:${cc};">${11-c}</h3>
    </c:forEach>

    函数
    <%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/functions" %>

    数据库操作
    <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>

    xml技术操作 用量较少
    <%@ taglib prefix="xml" uri="http://java.sun.com/jsp/jstl/xml" %>

    格式化标签库 掌握
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    <fmt:formatNumber minIntegerDigits="3" pattern="0.000" value="${i}"/>
    <fmt:formatDate value="${st.birthday}" pattern="MM月dd日"/>

    怕什么真理无穷,进一步有一步的欢喜
  • 相关阅读:
    【objective-c】字典快速转换为Model代码
    【objective-c】类目 延展 协议
    【objective-c】内存管理原则
    UI基础-UI基础控件(一)
    OC面向对象-OC基础早知道
    我对于编程培训班的一些看法
    如何为SQLSERVER查询分析器开启事务
    准备在博客园常驻了
    Spring学习(二)(1.Spring依赖注入的方式 2.依赖注入的类型 3.Bean的作用域 4.自动注入 5在Spring配置文件中引入属性文件6使用注解的方式 )
    Springmvc的常用注解
  • 原文地址:https://www.cnblogs.com/Mkady/p/7001715.html
Copyright © 2011-2022 走看看