struts2的s:iterator标记的使用.

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>My JSP 'registrySuccess.jsp' starting page</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">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    	<h2>从数据库表esb_admin_user_info后台检索出的结果如下:</h2><br/>
    	
    	<font color="red"><b>从request中取出集合输出:</b></font><br/>
    	<s:iterator var="userinfo" value="#request_userInfoList" id="userinfo">
    		<s:property value="#userinfo.username"/>
    		<s:property value="#userinfo.password"/>
    		<s:property value="#userinfo.groupname"/>
    		<s:property value="#userinfo.email"/>
    		<s:property value="#userinfo.status"/>
    		<br/>
    	</s:iterator>
    	<br/>
    	
    	<font color="red"><b>从session中取出集合输出:</b></font><Br/>
    	<s:iterator var="userinfo" value="#session.session_userInfoList" id="userinfo">
    		<s:property value="#userinfo.username"/>
    		<s:property value="#userinfo.password"/>
    		<s:property value="#userinfo.groupname"/>
    		<s:property value="#userinfo.email"/>
    		<s:property value="#userinfo.status"/>
    		<br/>
    	</s:iterator>
  </body>
</html>

 struts2中Action保存一个集合到request中,另外一个保存在session里面,在页面通过s:iterator标记输出.
 代码如下:

 

@SuppressWarnings("unchecked")
	public String registry(){
		List userInfoList = userInfoService.queryAllObject(EsbAdminUserInfo.class);
		
		//保存到session中;
		ActionContext.getContext().getSession().put("session_userInfoList", userInfoList);
		
		//保存到request中;
		ActionContext.getContext().put("request_userInfoList", userInfoList);
		
		System.out.println("UserInfo 大小:"+userInfoService.queryAllObject(EsbAdminUserInfo.class).size());
		System.out.println("注册方法!");
		return "success";
	}

 

 

 

在页面输出如下:

 

你可能感兴趣的:(iterator)