Jakarta ee 对象数组列表上的Struts 1.1逻辑迭代器
我有一个从txt文件RegistrationFormBean()读取的对象数组列表;是元素类型Jakarta ee 对象数组列表上的Struts 1.1逻辑迭代器,jakarta-ee,servlets,struts,javabeans,Jakarta Ee,Servlets,Struts,Javabeans,我有一个从txt文件RegistrationFormBean()读取的对象数组列表;是元素类型 public List getuserList() throws IOException{ InputStream input = new FileInputStream("log.txt"); int i=0; String temp[]=new String[5];
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并打印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页面中引用元素类型吗
请注意,对于我编写的代码,我只打印了第一列,其中包含“citta”,tmp中的“citta”是元素的最后一个属性,
我还进行了调试,正确加载了列表,因此我认为问题出在jsp页面上。您可以使用
标记访问嵌套属性。
要使用它,您需要在JSP页面中添加标记库:
<%@ taglib uri="/tags/struts-nested" prefix="nested"%>
thx这就是我想要的,在apache页面旁边,我在哪里可以找到一些关于定制struts标签的适当参考?
<nested:nest property="userList">
<!-- 'name' is just plain String, does not need a nested iteration -->
<nested:write property="name"/>
<!-- but 'cognome' has some inner properties, we are interested in exploring -->
<nested:iterate property="cognome">
<nested:write property="somePropertyOfCognome"/>
</nested:iterate>
</nested:nest>