Struts2 使用 标签迭代取值



----------------------------------------------------------sturts.xml

		<action name="FindAllusersAction" class="com.zyl.struts.action.impl.FindAllUserAction">
		<result name="list">/list.jsp</result>
		</action>
---------------------------------------------------------
package com.zyl.struts.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.junit.Assert;
import org.junit.Test;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.zyl.hiber.daoimpl.UsersDAOImpl;
import com.zyl.hiber.po.Users;
import com.zyl.spring.service.impl.UserServiceImpl;
import com.zyl.struts.action.ILoginAction;

public class FindAllUserAction {
	private List<Users> list ;
	
	
	public String execute() throws Exception {
		System.out.println("FindAllUserActionImpl 执行了");
	  List<Users> list = new ArrayList<Users>();
	  for (Long i = 1L; i <= 5; i++) {
	   Users user = new Users();
	   user.setUsersid(i);
	   user.setUsername("username" + i);
	   user.setPassword("password" + i);
	   list.add(user);
	  }
	  HttpServletRequest request = ServletActionContext.getRequest();
	  request.setAttribute("list", list);
	  System.out.println(list);
	  System.out.println(request);
	  return "list";

   }
}
------------------------------------------------------------


<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<body>
	欢迎
	
		<table align="center">
			<s:property value="users.username" />
			<form>
				<s:iterator value="#request.list">
					<tr>
						<td>
							<s:property value="usersid" />
						</td>
						<td>
							<s:property value="username" />
						</td>
						<td>
							<s:property value="password" />
						</td>
					</tr>
				</s:iterator>
				
			</form>
		</table>
		
	</body>
</html>
--------------------------------------------------------




你可能感兴趣的:(java,spring,jsp,struts,JUnit)