<%@ page contentType="text/html; charset=UTF-8" language="java" import="com.test.Content,java.util.*" errorPage="" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<link rel="stylesheet" href="inc/index.css" type="text/css" />
<jsp:useBean id="list" class="com.test.ListTest" scope="request"/><html> 
<style type="text/css">
<!--
#Layer4 {
position:absolute;
width:130px;
height:155px;
z-index:2;
left: -2px;
top: 364px;
}
#Layer1 {
position:absolute;
width:121px;
height:115px;
z-index:1;
left: 6px;
top: 392px;
}
A { text-decoration: NONE}
A:hover {border-bottom:1px dashed #ffffff }-->
    </style>
<head>
<title>JSP for LoginForm form</title>
</head>
<body>
<div id="Layer4"> <html:form action="/loginAction.do" method="POST">
 <logic:empty name="ok">
  <table width="134" height="151" border="0">
        <tr>
          <td width="146">a
  
  <table width="125" height="77" border="0">
            <tr>
              <td height="23"><table width="117" border="0">
                  <tr>
                    <td width="26">name</td>
                    <td width="72"><html:text property="username" size="10" style="width:70px; border:1px #ffffff dashed;"/></td>
                  </tr>
                </table>
                  <table width="117" border="0">
                    <tr>
                      <td width="26">pass</td>
                      <td width="72"><html:password property="password" size="15" style="width:70px; border:1px #ffffff dashed;"/></td>
                    </tr>
                  </table>
                <table width="117" border="0">
                    <tr>
                      <td><div align="right">
                          <html:submit value="Login"/>
                      </div></td>
                    </tr>
                </table></td>
            </tr>
          </table>
  <table width="125" border="0">
            <tr>
              <td><html:messages id="messages" message="true">
                <bean:write name="messages"/>
              </html:messages></td>
            </tr>
          </table></td>
        </tr>
    </table>
</logic:empty>
  </html:form>
</div>

<div id="Layer1">
 <logic:notEmpty name="ok">
  <table width="122" height="59" border="0">
        <tr>
          <td height="17"><html:link page="/user_Post.do" >
            <div align="center">[发表日记]</div>
          </html:link></td>
        </tr>
        <tr>
          <td height="17"><html:link page="/logoutAction.do" >
            <div align="center">[注销登录]</div>
          </html:link></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table>
  </logic:notEmpty>  
</div>

<DIV class=main id=layer style="OVERFLOW-Y: scroll; LEFT: 139px; OVERFLOW-X: hidden; WIDTH: 651px; POSITION: absolute; TOP: 14px; HEIGHT: 573px">

      <TABLE width=633 border=0>
        <TBODY>
          <TR>
            <TD >
                        <%for(Iterator iter = list.testSelect();iter.hasNext();){
            Content content1=(Content)iter.next();
          %>
           
            </TD>
          </TR>
          <TR>
            <TD >[日记标题]<%=content1.getTitle() %></TD>
          </TR>
          <TR>
            <TD ><%=content1.getContent() %></TD>
          </TR>
          <TR>
            <TD ><div align="right"><%=content1.getDatetime() %></div></TD>
          </TR>
          <TR>
            <TD >------------------------------------------------------------------------------------------------------------------------------------------------------------</TD>
          </TR>
          <TR>
            <TD><DIV align=center></DIV></TD>
          </TR> <%} %>
        </TBODY>
      </TABLE>
     </DIV>
</body>
</html>
--------------------------------------------------------------------------
<jsp:useBean id="list" class="com.test.ListTest" scope="request"/>
       
 <%for(Iterator iter = list.testSelect();iter.hasNext();){
            Content content1=(Content)iter.next();
          %>
<%=content1.getTitle() %><%} %>
-----------------------------------------------------------------------------
请问用struts标签的话该如何写呢,上面的语句。
usebean创建一个listtest类的list对像然后调用listtest类的testsestct方法反回一个iterator类型对象。
然后在FOR循环输出,可是不知道怎么用struts的标签现实。在百度也找了半天,关键字也没搜到几个,希望各位大大指教。

解决方案 »

  1.   

    把值存到一个list里,然后传到jsp,向下面这样循环。
    <logic:iterate id="site" name="listname">
      <logic:present name="site">
        <bean:write name="site" property="id"/>
        <bean:write name="site" property="name"/>
        <bean:write name="site" property="email"/>
      </logic:present>
    </logic:iterate>
      

  2.   

    <logic:iterate id="site" name="listname">取的是不是session的对象?我想用userbean的对象调用方法然后返回一个list,用这个可以实现嘛。
    <logic:iterate id="site" name="listname">
      <logic:present name="site">
        <bean:write name="site" property="id"/>
        <bean:write name="site" property="name"/>
        <bean:write name="site" property="email"/>
      </logic:present>
    </logic:iterate>
      

  3.   

    <%
       Vector v=new Vector();
       v.add("zhangsan");
       v.add("lisi");
       v.add("wangwu");
       request.setAttribute("names",v);
    %>
    <logic:iterate id="name" name="names">
      <bean:write name="name"/>
    </logic:iterate>
      

  4.   

    UserBean的list格式必须是这样的
    public class UserBean{
      private List list=new Vector();
      
      public void setList(List list){
         this.list=list;
      }  public List getList(){
         return this.list;
      }
    }<%
       Vector v=new Vector();
       v.add("zhangsan");
       v.add("lisi");
       v.add("wangwu");
       request.setAttribute("names",v);
       UserBean userbean=new UserBean();
       userbean.setList(v);
       
       request.setAttribute("userbean",userbean);
    %><logic:iterate id="name" name="userbean" property="list">
      <bean:write name="name"/>
    </logic:iterate>