jsp怎么创建list


当前第2页 返回上一页

案例:在JSP中遍历LIST列表

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<%

   List<String> list = new ArrayList<String>();

   list.add("简单是可靠的先决条件");

   list.add("兴趣是最好的老师");

   list.add("知识上的投资总能得到最好的回报");

   request.setAttribute("list", list);

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<base href="<%=basePath%>">

<title>Jsp使用c:forEach遍历List集合</title>

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

</head>

<body>

<b>遍历List集合的全部元素:</b>

<br>

<c:forEach items="${requestScope.list}" var="keyword" varStatus="id">

    ${id.index} ${keyword}<br>

</c:forEach>

<br>

<b>遍历List集合中第一个元素以后的元素(不包括第一个元素):</b>

<br>

<c:forEach items="${requestScope.list}" var="keyword" varStatus="id" begin="1">

${id.index} ${keyword}<br>

</c:forEach>

</body>

</html>

以上就是jsp怎么创建list的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

javascript和JSP有什么区别

JSP怎么导入css

JSP怎么显示pdf文件

JSP写javascript用什么标签

JSP css不起作用怎么办

bootstrap怎么在JSP使用方法

三分钟带你了解js和JSP的区别

?JSP日历表格怎么做

JSP和javascript是一个东西吗

JSP和html之间有什么区别

更多相关阅读请进入《JSP》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...