本帖最后由 Fishing_Moon 于 2011-06-27 16:25:22 编辑

解决方案 »

  1.   

    LZ下面的两个 <c:forEach>中第一个循环三个tr、而后面一个还是用同样的变量取值来循环同一个Table的tr为什么不直接用一个标签循环整个Table呢!
    还有、我现在也有一个疑惑、就是关于EL表达式就近原则的疑惑、不知道它有没有、!如果没有的话、那么LZ的写法是存在问题的!如果有、那么就是变量中没有值、所以看不到效果!
      

  2.   

    下段代码可以改为:
    <table width="440" border="0" cellspacing="0" cellpadding="0" class="xw_table" align="center">  <c:set var="newsjhdt" value="${newsjhdt}"/>
      <c:set var="newsjhdt2" value="${newsjhdt}"/>  <c:forEach items="${newsjhdt}" var="newsjhdt" begin="0" end="0">
      <c:set var="str" value="${newsjhdt.contents}"/>
      <tr>
      <td colspan="2" height="30" style="color:#CC0000; font-size:14px; font-weight:bold; text-align:center;">
      ${newsjhdt.title }
      </td>
      </tr>
      <tr>
      <td colspan="2" style="line-height:20px;">
      <c:choose>
    <c:when test="${fn:length(str) > 70}">
    <c:out value="${fn:substring(str,0,70 )}..."></c:out>
    </c:when>
    <c:otherwise>
      <c:out value="${str}"></c:out>
    </c:otherwise>
    </c:choose>
      </td>
      </tr>
      <tr>
      <td colspan="2" height="15" align="center"><img src="<%=path %>/images/wxb_59.jpg"></td>
      </tr>
      </c:forEach>
      <c:forEach items="${newsjhdt2}" var="newsjhdt2" begin="1" end="5">
      <tr>
      <td width="375" height="22"><a href="<%=path%>/front/WxNewsDetailServlet?newsid=${newsjhdt2.newsid}">${newsjhdt2.title }</a></td>
      <td width="65">${newsjhdt2.contents }</td>
      </tr>
      </c:forEach>
     </table>
    或者像前段代码一样将SET集合放入Foreach中,将Foreach获取的同一对象放入set中,再通过set定义的不同对象来获取。