功能:  用户登录以后跳转到下一个页面,从数据库中取出所有的用户并显示出来 我写了两个DB类 取得数据库连接和获得结果集 在action的execute()方法里面得到了resultSet问题:  怎么把resultSet传到 result.jsp 并且用s:iterate 标签全部显示出来啊???
先谢谢了

解决方案 »

  1.   

    你用的struts2?有两种方式:
    1。 把Result定义为一个类的成员变量,并提供get方法。 然后在页面
        <c:forEach  items="${resultSet}" var="data">
               ${data.字段名}
        </c:forEach>2.用request.setAttribute();
          其它不变
      

  2.   

    <s:terate value="resultSet" id="id">
      <s:property value="key"/>:
      <s:property value="value"/>
    </s:iterate>
      

  3.   

    把结果集存入request里,
    HttpServletRequest request=ServletActionContext.getRequest();
    在通过转发给页面,<table>
    <s:iterator value="#request.存入request里的集合名">
    <tr>
    <td><s:property value="该集合实体属性名"/></td>
    <td><s:property value="该集合实体属性名"/></td>
    </tr>
    </s:iterator>
    </table>
      

  4.   

    [Quote=引用 1 楼 zl3450341 的回复:]
    你用的struts2?必须是啊,我去试试看,ResultSet都能传过去太牛了
      

  5.   

    [Quote=引用 3 楼 quanlei1507053 的回复:]
    把结果集存入request里,
    HttpServletRequest request=ServletActionContext.getRequest();
    在通过转发给页面,<table>
     上面这一步能说详细点吗
      

  6.   

    各位大神我说的ResultSet 是数据库的ResultSet啊 是rs = preparedStatement.executeQuery();
    得到的结果啊!!!!
      

  7.   


    2.用request.setAttribute();或者是session.setAttribute  
    还是第一种方式比较好些  
    也可以用<s:forwzch  ----
      其它不变
      

  8.   


    我晕 这个是不可以的。 你必须在后台把resultSet进行解析,然后封装成数组,或者集合,再传到前台
      

  9.   

    你应该是用jdbc查询的吧,你获得的结果集resultSet它是一种接口,你可以通过next()取得记录,把这个记录add到你的list里然后把这个list存入request里,后面就是一样的步骤
      

  10.   

    把ResultSet挨条取出来放到数组或者List,然后在action中request.setAttribute("name",List)放进去,然后在页面中List  list=(List)request.getAttribute("name");取出来,再循环显示
      

  11.   

    不知道用哪个容器好啊???有三个属性 id username password
      

  12.   

    说实话,虽然jdbc是最底层的东西,性能是最好的,但是如果项目不是很大的话,用hibernate写hql舒服些,用jdbc查询一个集合set起一大堆,我搞个屁啊,麻烦死了
      

  13.   

    给你贴出我有个类似的,要吧参考
    <div class="f_box">      
    <s:form action="page_pagination?subid=%{subid}&showTitle=%{showTitle}" method="post">
    标题:
    <input id="btname" name="btname" value="" type="text" style="width:120px;" height="18" maxlength="20" class="input_txt"/>
    <s:submit value="查询"/>
    </s:form>
    </div>
    <div class="space_10"></div>
    <div class="c_box">      
      <table width="100%">
         <thead>
         <tr> 
           <!-- <td>序号</td> -->
           <td>标题</td>
           <td>发布时间</td>
         </tr>
         </thead>
         <s:iterator value="list" id="li">
          <tr onmouseover="this.className='c2'" onmouseout="this.className='c1'">
               <!--<td><s:property value="#li.id"/></td> -->
              <td>
              <a target="_blank" href="<%=basePath%>index/index_getIndexById.action?id=<s:property value="#li.id"/>&leaf=<%=sname==""?"":sname+">" %><%=name %>"><s:property value="#li.title"/></a>
              </td> 
              <td><s:property value="#li.sj"/></td>
          </tr>  
         </s:iterator>
        
      </table>   
    </div><!-- =================================分页================================ -->
    <div class="space_10"></div>       
    <div class="p_box">      
       
        
       <s:if test="listSize!=1"> 
        <s:url action="page_pagination?subid=%{subid}&btname=%{btname}&pag=1&name=%{name}&showTitle=%{showTitle}" id="homePage">
          <s:param name="pageNow">1</s:param>
        </s:url>
        <s:a href="%{homePage}">首页</s:a>    <!-- 这是上一页的链接 --> 
        <s:url action="page_pagination?subid=%{subid}&btname=%{btname}&pag=1&name=%{name}&showTitle=%{showTitle}" id="previousPage" >
           <s:param name="pageNow">${pageNow-1}</s:param>
        </s:url>
       <s:if test="pageNow!=1"> 
        <s:a href="%{previousPage}">上一页</s:a> 
       </s:if>      
         <s:bean name="org.apache.struts2.util.Counter" id="counter">  
         <s:param name="first">${pageNow}</s:param>  
         <s:param name="last">${pageNow+2}</s:param>
         <s:iterator>  
           <s:if test=" (pageNow!=pageCount)&&(pageNow = pageNow+1)">
             <s:url action="page_pagination?subid=%{subid}&btname=%{btname}&pag=1&name=%{name}&showTitle=%{showTitle}" id="currentPage">
                <s:param name="pageNow">${pageNow}</s:param>
             </s:url>
             <s:a href="%{currentPage}">${pageNow}</s:a> 
           </s:if>
         </s:iterator>  
         </s:bean>     
        <!-- 下一页 --> 
         <s:url action="page_pagination?subid=%{subid}&btname=%{btname}&pag=1&name=%{name}&showTitle=%{showTitle}" id="nextPage">
            <s:param name="pageNow">${pageNow+1}</s:param>
         </s:url>     
         <s:if test="pageNow!=pageCount">
            <s:a href="%{nextPage}">下一页</s:a>
         </s:if>
        
        <!-- 尾页 -->
        <s:url action="page_pagination?subid=%{subid}&btname=%{btname}&pag=1&name=%{name}&showTitle=%{showTitle}" id="endPage">
          <s:param name="pageNow">${pageCount}</s:param>
        </s:url>
        <s:a href="%{endPage}">尾页</s:a>
        
        </s:if>
    </div>    
      

  14.   

    不知道用哪个容器好啊???有三个属性 id username password怎么封装啊 ????
      

  15.   

    Public class User{
    private Integer id;
    private String username;
    private String password;//生成三个属性的set get方法}//定义一个查询所有用户的接口
    interface UserDao{
      public List<User> findAllUser();
    }//见一个类实现这个接口
    public class UserDaoImpl implements UserDao{
     public List<User> findAllUser(){
    //JDBC连接数据库操作我就不写了
    String str = "select * from t_user";
    最后通过查询得到的结果集ResultSet对象转化为List<User>对象}
    }//Action中放一个UserDao属性并set get它,execute()方法中:
    List<User> list = (List<User>)this.getUserDao().findAllUser();
    request.setAttributer("list",list);//jsp页面显示所有用户:
    <tr>
    <td>id</td>
    <td>username</td>
    <td>password</td>
    </tr>
    <s:iterator value="#request.list" var="u">
    <tr>
    <td><s:property value="#u.id"/></td>
    <td><s:property value="#u.username"/></td>
    <td><s:property value="#u.password"/></td>
    </tr>
    </s:iterator>