JSP traversal backstage pass over the LIST__JS

Source: Internet
Author: User

1: Use Jstl tags (can be used with custom tags)

First refer to Jstl label

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


Then use the foreach label

<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" >

You can use <c:if test= "${not Empty list}" ></c:if> and <c:if test= "${not Empty list}" ></c:if> to handle null cases. If not null, display values, empty words, show no records, and so on.

The background can put the list to the value stack or to the request. For example: Request.setattribute ("list", xxxxlist);

2: Use JSP inline Java code traversal list (in the background of the list into the session, if it is a large amount of data, should not use this method)

First in the background to put the list into the session

Request.getsession (). setattribute (data.allnewslist, list);

The red Mark Data.allnewslist is defined as a constant in the data class under the Com.xiami.onlineshop.common package

public static final String allnewslist= "Allnewslist";



JSP Code: (Note the red code do not forget to introduce the corresponding class)

<%@ page language= "java" import= "Java.util.*,com.xiami.onlineshop.common.*,com.xiami.onlineshop.data.*" pageencoding= "GBK"%> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >  



3: Use Struts tab


<%@ 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]"/>															</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>


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.