1:使用jstl标签 (可以和自定义标签配合使用)

首先引用jstl标签

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

然后使用foreach标签

<c:forEach items="${list}" var="user" varStatus="vs">
<tr> <td>
<s:property value="#vs.index+1"/>
</td>
<td align = "center">${user.PId}</td>
<td align = "center">${user.PLoginname}</td>
<td align = "center">${user.PUserName}</td>
<td align = "center">${user.PEmail}</td>
<td align = "center"><html:department pdeptid="${user.PDeptid}"></html:department></td> <!-- 自定义标签 -->
</tr>
</c:forEach>

可以用<c:if test="${not empty list}"></c:if>   和 <c:if test="${not empty list}"></c:if> 来处理是否为空的情况。如果不为空,显示值,为空的话,显示无记录等。

后台可以把list放到值栈或者放到request.例如:request.setAttribute("list", XXXXlist);

2:使用jsp内嵌Java代码遍历List (在后台把List放到session中,如果是大数据量,不应使用此方法)

首先在后台把list放入到session中

request.getSession().setAttribute(<span style="color:#ff0000;">Data.ALLNEWSLIST</span>, list);

红色标记的Data.ALLNEWSLIST 为常量 在com.xiami.onlineshop.common包下的Data类中定义

public static final String ALLNEWSLIST="ALLNEWSLIST";

jsp代码:

<%@ page language="java" import="java.util.*,<span style="color:#ff0000;">com.xiami.onlineshop.common.*,com.xiami.onlineshop.data.*" </span>pageEncoding="GBK"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head> </head> <body>
<%
String ntype=null;
int pagenum=1;
if(request.getParameter("pagecurrent")!=null){
pagenum=Integer.parseInt(request.getParameter("pagecurrent"));
}
List list=null;
if(session.getAttribute(Data.ALLNEWSLIST)!=null){
list = (List)session.getAttribute(Data.ALLNEWSLIST);
int l = list.size();
%>
<table border=1 width="100%">
<tr bgcolor="#8E8E8E">>>首页>商城动态</tr>
</table> <br><br> </font></center>
<font color=#272727>第<%=pagenum %>页<Br><br></font>
<table>
<%
for(int i=0;i<l;i++){
News news =(News)list.get(i);
ntype=news.getNtype(); %>
<tr bgcolor="#93FF93">
<td bgcolor="#6C6C6C"><%=news.getNid() %></td>
<td bgcolor="#ADADAD"><a href="servlet/ShowDetailNews?nid=<%=news.getNid() %>"><%=news.getNtitle() %></a></td> </tr>
<%
}
%> </table><br>
<a href="servlet/ShowAllNews?page=1&type=<%=ntype %>">首页</a>
<a href="servlet/ShowAllNews?page=<%=pagenum-1 %>&type=<%=ntype %>">上一页</a>
<a href="servlet/ShowAllNews?page=<%=pagenum+1 %>&type=<%=ntype %>">下一页</a>
<a href="servlet/ShowNewsEndPage?type=<%=ntype %>">尾页</a> <%
}
%>
</body>
</html>

3:使用Struts标签

<%@ taglib prefix="s" uri="/struts-tags"%>
<s:iterator value="#request.userList" status="stat" id="sd">
<tr align="center">
<td>
<s:property value="#sd[6]" />
</td>
<td>
<s:property value="#sd[1]" /> <span style="WHITE-SPACE: pre"> </span></td>
<td>
<s:property value="#sd[2]"></s:property>
</td>
<td>
<s:property value="#sd[4]"></s:property>
</td>
<td>
<s:property value="#sd[5]"></s:property>
</td>
</tr>
</s:iterator>

Jsp遍历后台传过来的List的更多相关文章

  1. JSP向后台传 递 参 数 的四种方式

    一.通过Form表单提交传值 客户端通过Form表单提交到服务器端,服务器端通过 Java代码 request.getParameter(String xx); 来取得参数(xx)为参数名称.通过ge ...

  2. jQuery中使用$.each()遍历后台响应的json字符串问题

    今天在做练习项目的时候,使用$.each()方法遍历后台传过来的json字符串时,chrome浏览器中发现如下问题  Cannot use 'in' operator to search for 'l ...

  3. html表单通过关联数组向php后台传多条数据并遍历输出

    通过表单向php后台传多条数据,以关联数组方式呈现,废话不多说,代码附上: html表单代码,方式我设置为get: <form action="php/cart.php" m ...

  4. Web jsp开发学习——前端后台传参方法

    一.前端传后台: 1.1表单数据的传递   前端的表单里定义名字name   后台通过名字获取输入的值         1.2页面点击了哪个按钮传递 登录注销的另一种方式   点击登录的地方设置参数 ...

  5. jsp页面获取后台传过来的list集合的长度

    在jsp页面导入函数标签库: <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"% ...

  6. MVC后台传dt数据

    //MVC后台传dt数据 public JsonResult TeacherVoteInfo([FromBody]Teacher_VoteModel model) { string tname = m ...

  7. 不用外部JAR包,自己实现JSP文件上传!

    看书上(JSP应用与开发技术)使用JSP文件上传,写了个真无语,压根就有很多问题,上传500KB的文件传过去后只剩350KB,而且编码必须是GBK.GB2312,否则传过去的文件都数据截取不正确. 琢 ...

  8. JSP 文件上传

    JSP 文件上传 JSP可以通过HTML的form表单上传文件到服务器. 文件类型可以是文本文件.二进制文件.图像文件等其他任何文档. 创建文件上传表单 接下来我们使用HTML标签来创建文件上传表单, ...

  9. JSP-Runoob:JSP 文件上传

    ylbtech-JSP-Runoob:JSP 文件上传 1.返回顶部 1. JSP 文件上传 JSP 可以与 HTML form 标签一起使用,来允许用户上传文件到服务器.上传的文件可以是文本文件或图 ...

随机推荐

  1. asp.net core webapi项目配置全局路由

    0.目录 整体架构目录:ASP.NET Core分布式项目实战-目录 一.前言 在开发项目的过程中,我新创建了一个controller,发现vs会给我们直接在controller头添加前缀,比如[Ro ...

  2. 在BAE上部署Pomelo

    BAE升级到3.0后顿时感觉好用了很多,俨然云主机的感觉. 底下我将分享我在BAE上部署Pomelo的过程. 首先需要拥有一个BAE的执行单元.没有的可以自行百度并部署. 接着svn得出代码到本地.此 ...

  3. 深入解析QML引擎, 第4部分: 自定义解析器

    原文 QML Engine Internals, Part 4: Custom Parsers ——————————————————————————————————————————— 上一篇 绑定类型 ...

  4. Jenkins+git+Nginx

    1.Jenkins 一.tomcat安装 1.下载JDK和Tomcat //通过wget下载 wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomca ...

  5. Power Designer逆向工程导入Oracle表,转为模型加注释

    1.打开PowerDesigner ——文件——Reverse Engineer——DataBase 2.选择所要连接数据库版本,此处使用的是oracle version 11g. 3.点击红色区域, ...

  6. mysql把一字段拆分为多行

    sql语句 select a.house_no as '房子',substring_index(substring_index(a.name,',',b.help_topic_id+1),',',-1 ...

  7. 第五次ScrumMeeting博客

    第五次ScrumMeeting博客 本次会议于10月29日(日)22时整在3公寓725房间召开,持续15分钟. 与会人员:刘畅.辛德泰.窦鑫泽.张安澜.赵奕. 1. 每个人的工作(有Issue的内容和 ...

  8. Python Requests库入门——应用实例-百度、360搜索关键词提交

    百度的关键词接口: http://www.baidu.com/s?wd=keyword 360的关键词接口: http://www.so.com/s?q=keyword keyword就是需要查找的关 ...

  9. WCF传送大数据时的错误“ 超出最大字符串内容长度配额”

    格式化程序尝试对消息反序列化时引发异常: 尝试对参数 http://tempuri.org/ 进行反序列化时出错: GetLzdtArticleResult.InnerException 消息是“反序 ...

  10. int 和 Integer的区别

    int是基本类型,默认值为0,int a=5;a只能用来计算,一般作为数值参数. Integer是引用类型,默认值为null, Integer b=5;b是一个对象,它可以有很多方法,一般做数值转换, ...