• JSP总结(jsp/EL表达式/核心标签)


    1、概念

      jsp,即java Server Pages,java服务器页面。

    2、简单介绍

      小示例

     1 <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
     2 <!DOCTYPE html>
     3 <html lang="zh-CN">
     4 <head>
     5 <title>问候页面</title>
     6 </head>
     7 <body>
     8 Hello World!<br/>
     9 </body>
    10 </html>

    上述代码中,第一行为解决中文编码问题

    3、EL表达式

      EL,Expression Language,为使jsp更加简单。

      a.普通界面赋值——获取数据

        ${标识符}

    < %=request. getParameter(“username”)% > 等价于 ${ param. username }

      b.执行运算

        ${运算表达式}

    ${user==null? "对不起,您没有登陆 " : user.username}

      

    4、jsp标签

     常用核心标签

    <c:if>:单一if判断语句

    1 <c:if test="<boolean>" var="<string>" scope="<string>">
    2    ...
    3 </c:if>
    //var与scope非必填,一般仅仅用到test判断,var用于存储条件结果的变量,scope var属性的作用域

    <c:choose> <c:when> <c:otherwise>:在众多选项中做出选择

     1 <c:choose>
     2     <c:when test="<boolean>">
     3         ...
     4     </c:when>
     5     <c:when test="<boolean>">
     6         ...
     7     </c:when>
     8     ...
     9     ...
    10     <c:otherwise>
    11         ...
    12     </c:otherwise>
    13 </c:choose>

    <c:forEach>:迭代一个集合中的对象

    1 <c:forEach items="list" var="item" begin="1" varStatus="status" >
    2    <input value="${item.productId }" id='productId${status.index + 1}'/>
    3 </c:forEach>
    //items是要被循环的信息,begin是开始的元素(0=第一个元素,1=第二个元素),var代表当前条目的变量名称,varStatus代表循环状态的变量名称

    常用格式化标签

    <fmt:formatDate> :格式化日期和时间

    1 <fmt:formatDate pattern="yyyy-MM-dd HH:mm:ss" value="${now}" />

    <fmt:formatNumber>:数 精度格式化

    1 //groupingUsed="false"是否有分组符,即3位一个逗号
    2 //maxIntegerDigits 整数位几位
    3 //maxIntegerDigits 小数位几位
    4 //pattern 类型模式 percent或number或currency等
    5 <fmt:formatNumber type="number" pattern="0.00" maxFractionDigits="2" />

     除了上述两种标签外,还有SQL标签和XML标签,但较少使用

    JSTL函数

    fn:length():字符串长度

    1 ${fn:length(order.List) }

    fn:split():将字符串用指定的分隔符分隔然后组成一个子字符串数组

    1 //两个函数一起用的例子
    2 ${fn:length(fn:split(codeListstr,','))}
  • 相关阅读:
    POJ 1837 Balance 水题, DP 难度:0
    POJ 3126 Prime Path bfs, 水题 难度:0
    python学习笔记day01 练习题
    python学习笔记day01_08 循环语句while
    python学习笔记day01_07 流程控制语句
    python学习笔记day01_06 基础数据类型
    python学习笔记day01_05 运行py程序--常量,变量,注释
    python学习笔记day01_04 python分类
    python学习笔记-day01_02计算机基础
    PAT 甲级 1134 Vertex Cover
  • 原文地址:https://www.cnblogs.com/huasky/p/9504753.html
Copyright © 2020-2023  润新知