想要尝试显示多行数据时候
我先定义
一个包含t1 和 t2 getter setter方法的Test.java 放在app包下
然后定义一个Action
public class ShowAction extends Action
{
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ActionErrors errors = new ActionErrors();
        ActionForward forward = new ActionForward(); // return value
        Test test = (Test) form; 
        ArrayList tests = new ArrayList();
        int i = 0;
        for (i=0;i<4;i++)
        {
         test.setT1("1");
         test.setT2("2");
         tests.add(test);
        }      
        forward = mapping.findForward("t");
        return (forward);
    }
}
在forward到的jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%>
<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template"%>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<html:html>
<HEAD>
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<META http-equiv="Content-Type" content="text/html; charset=GB18030">
<META name="GENERATOR" content="IBM Software Development Platform">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="theme/Master.css" rel="stylesheet" type="text/css">
<TITLE></TITLE>
</HEAD>
<BODY>
<logic:iterate id = "test" name="tests" property = "app.Test">
<bean:write name = "test" property = "t1"/>
<bean:write name = "test" property = "t2"/>
</logic:iterate>
</BODY>
</html:html>
就会显示 无法显示网页如果将logic:iterate去掉
<BODY>
<bean:write name = "test" property = "t1"/>
<bean:write name = "test" property = "t2"/>
</BODY>
则能显示出 1 和2 
这是什么问题啊??

解决方案 »

  1.   

    tests根本没传到页面上,当然会出错了
      

  2.   

    那要如何将tests 传到页面上去呢?
      

  3.   

    在forward前加request.setAttribute("tests",tests);
      

  4.   

    楼上正解!
    JSP页面上的Tag的属性都是通过request和session传到页面上的。
            ArrayList tests = new ArrayList();
            int i = 0;
            for (i=0;i<4;i++)
            {
            test.setT1("1");
            test.setT2("2");
            tests.add(test);
            } 
           request.setAttribute("tests",tests);
    这样应该就可以了!
      

  5.   

    <logic:iterate id="element" indexId="index" name="ArticleInfo">
    比如这句的意思大概是 在request范围以内寻找有没 ArticleInfo 这个对象,有的话就 将ArticleInfo 里面的元素一个一个取出来,用element来表示,通过element能取到一些东西