2
我有一個ArrayList的對象,我從txt文件中讀取RegistrationFormBean();爲元素類型Struts 1.1邏輯迭代器在對象的ArrayList上
public List getuserList() throws IOException{
InputStream input = new FileInputStream("log.txt");
int i=0;
String temp[]=new String[5];
tmp= new RegistrationFormBean();
BufferedReader in = new BufferedReader(new FileReader("log.txt"));
while ((str = in.readLine()) != null) {
StringTokenizer st = new StringTokenizer(str,"\t\t");
while(st.hasMoreElements()){
temp[i]=st.nextElement().toString();
}
tmp.setName(temp[0]);
tmp.setCognome(temp[1]);
tmp.setCitta(temp[4]);
tmp.setDdnascita(temp[2]);
tmp.setCodfisc(temp[3]);
userList.add(tmp);
}
in.close();
return userList;
}
這是JSP頁面應該迭代ArrayList返回並打印屬性的
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<jsp:useBean id="userList" scope="request" class="com.webagesolutions.struts.actions.query"/>
<html:html>
<HEAD>
<%@ page
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM WebSphere Studio">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="theme/Master.css" rel="stylesheet" type="text/css">
<TITLE></TITLE>
</HEAD>
<BODY>
<table border=1>
<logic:iterate name="userList" id="nextElement" property="userList">
<tr>
<td><bean:write name="nextelement" property="name"/></td>
<td><bean:write name="nextElement" property="cognome"/></td>
<td><bean:write name="nextElement" property="ddnascita"/></td>
<td><bean:write name="nextElement" property="codfisc"/></td>
<td><bean:write name="nextElement" property="citta"/></td>
</tr>
</logic:iterate>
</table>
</BODY>
</html:html>
所以我不知道如何訪問元素的數組列表中的每個元素的下一個元素,假設屬性是element.name element.cognome element.ddnascita(元素的屬性),我應該在類中定義一些讀取txt文件的getter? 我應該引用jsp頁面中的元素類型嗎?
請注意,隨着我寫的代碼,我只得到第一列打印,它包含我的tmp中的「citta」,是元素的最後一個屬性, 我也做過調試和列表得到正確加載,所以我想這個問題是在jsp頁面。
THX是我所期待的是,apache的頁面旁邊我在哪裏可以找到關於定製Struts標籤一些像樣的參考? – 2012-03-10 20:45:20