首页 > 其他分享 >JSTL练习

JSTL练习

时间:2022-12-18 14:45:11浏览次数:39  
标签:count name age 练习 JSTL user

JSTL练习

需求:在request域中有一个存有User对象的List集合。需要使用jstl+el将list集合数据展示到jsp页面的表格table中

<%@ page import="cn.itcast.domain.User" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Date" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>
<head>
    <title>test</title>
</head>
<body>

<%

    List list = new ArrayList();
    list.add(new User("张三",23,new Date()));
    list.add(new User("李四",24,new Date()));
    list.add(new User("王五",25,new Date()));

    request.setAttribute("list",list);


%>

<table border="1" width="500" align="center">
    <tr>
        <th>编号</th>
        <th>姓名</th>
        <th>年龄</th>
        <th>生日</th>
    </tr>
    <%--数据行--%>
    <c:forEach items="${list}" var="user" varStatus="s">

        <c:if test="${s.count % 2 != 0}">

            <tr bgcolor="red">
                <td>${s.count}</td>
                <td>${user.name}</td>
                <td>${user.age}</td>
                <td>${user.birStr}</td>
            </tr>
        </c:if>

        <c:if test="${s.count % 2 == 0}">

            <tr  bgcolor="green">
                <td>${s.count}</td>
                <td>${user.name}</td>
                <td>${user.age}</td>
                <td>${user.birStr}</td>
            </tr>
        </c:if>




    </c:forEach>

</table>






</body>
</html>

 

标签:count,name,age,练习,JSTL,user
From: https://www.cnblogs.com/yuzong/p/16990369.html

相关文章

  • EL-empty运算符&隐式对象pageContext、JSTL概述
    EL-empty运算符空运算符:empty功能:用于判断字符串、集合、数组对象是否为null或者长度是否为0${emptylist}:判断字符串、集合、数组对象是否为null或者长度为0......
  • 图书管理系统(重要练习)
    图书管理系统图书管理系统前期准备1.表设计 第一张图:先考虑普通字段再考虑外键字段第二张图:mysql数据库配置数据库迁移'''python38manage.pymak......
  • wallhaven.cc网页爬取图片练习
    importosimportreimportrequestsurl="https://wallhaven.cc/search?q=id:12757&sorting=random&ref=fp"#反爬措施#暂无#获取网页内容response=requests.get(url)res......
  • Python - 习题练习(1-3)
    一、前言接下来通过一些习题练习下代码感,以及熟悉解题思路和基本函数使用,参考博客:https://www.cnblogs.com/poloyy/p/15255670.html二、习题实战1、open函数、字典.......
  • 入门练习4-3
    #define_CRT_SECURE_NO_WARNINGS#include<stdio.h>intmain(){inta=0;printf("请输入一个正整数:");scanf("%d",&a);while(a>=0){printf("%d",a);a-......
  • 入门练习4-4
    #define_CRT_SECURE_NO_WARNINGS#include<stdio.h>intmain(){inta=0;printf("请输入一个正整数:");scanf("%d",&a);while(a>=1){printf("%d",a);......
  • 多表查询练习
    --部门表CREATETABLEdept(idINTPRIMARYKEYPRIMARYKEY,--部门iddnameVARCHAR(50),--部门名称locVARCHAR(50)--部门所在地);--添加4个部......
  • 入门练习4-1
    #define_CRT_SECURE_NO_WARNINGS#include<stdio.h>intmain(){ inta=0,b=0; do{ printf("请输入一个整数:"); scanf("%d",&a); if(a<0) {  ......
  • 入门练习4-2
    实话说,这题不会看了答案也不会,CSDN社区的答案是用do语句解答的,有些符号看不懂 sum+=a;a++;超了明解这本书的纲,而且运行结果是错的,如图#define_CRT_SECURE_NO_WARNINGS#......
  • 2.python-练习(日期-函数式编程)
    计算活的天数"""定义函数,根据生日(年月日),计算活了多天"""fromdatetimeimportdatetimedefcalculate_alive_day(year:int,month:int,day:int)->int:......