通过request.setAttribute("NewsTopicList", 从数据库读出来的新闻标题集合);
然后通过标签
<logic:notEmpty name="NewsTopicList">
   <logic:iterate id="topic" name="NewsTopicList">
          <html:link page="lookNews.do" paramId="id" paramName="topic" paramProperty="id">
              <bean:write name="topic" property="新闻from中标题的属性名"/>
          </html:link>
   </logic:iterate>
</logic:notEmpty>

解决方案 »

  1.   

    不好意思,没看请题目...
    你说的那种一对多的迭代显示吧...
    用struts标签实现不了,得用JSTL标签
    你先把所以的新闻分类读出来
    再把所以的新闻读出来
    根据
    <%
    request.setAttribute("NewsTopicList", 从数据库读出来的新闻标题集合);
    request.setAttribute("NewsList", 从数据库读出来的新闻集合);%>
    <table>
    <c:forEach items="${NewsTopicList}" var="NewsTopicList">
    <tr>
    <td align="center">

    <c:out value="${NewsTopicList.topicname}" /> 
    </td>
    <td align="center">
    <c:forEach items="${NewsList}" var="NewsList">
    <c:if test="${NewsList.NewsTopic.id==NewsList.id}">
    <c:out value="${NewsList.newsname}" />
    </c:if>
    </c:forEach>
    </td>
    </tr>
    </c:forEach>
    </table>
      

  2.   

    既然您的 新闻都是放在一个表中,是根据新闻类别不一样而分的. 那不同的新闻类别 肯定有特定标识符
    ,例如 C 代表 代表程序员新闻。。则您的页面那个 程序员新闻模块那里 应该有个 Hidden 标签记录您的这个 模块的标识 C  <input type="hidden" value="C">  后台读取之后 们就可以根据 这个Hidden的值放入 不同的Sesion中咯--或则根据这个标识 存入响应的字段中。不知道回答对吗?希望能帮到您。
      

  3.   

    后台查询的时候只查最新的8条,通过request.setAttribute("NewsTopicList", 从数据库读出来的新闻标题集合);
      

  4.   

    我要的不是在前台怎么去显示这个集合我是要在后台怎么去实现这个读取数据,新闻我是按照类别分的,每次读出的时候是怎么存入到arrylist呀? 先存入到哪儿 ,再存入到arrylist中的呢?
      

  5.   

    ...
    给你个例子/* 连接数据库 */
    package com.lhzx.db;import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;public class DBConn {

    public Connection conn;

    public  ResultSet rs;

    public DBConn(){
    try {
    Class.forName("com.mysql.jdbc.Driver");
     conn = DriverManager.getConnection(
    "jdbc:mysql://127.0.0.1:3306/news", "root", "mysql");
    } catch (SQLException ex) {
    ex.printStackTrace();
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    }
    }
    }/** Bean类 **/
    package com.lhzx.db;public class News {
    private int id; private String topic; private String issuename; private String issuetime; private String content; private String picture; /**
     * @return the content
     */
    public String getContent() {
    return content;
    } /**
     * @param content the content to set
     */
    public void setContent(String content) {
    this.content = content;
    } /**
     * @return the id
     */
    public int getId() {
    return id;
    } /**
     * @param id the id to set
     */
    public void setId(int id) {
    this.id = id;
    } /**
     * @return the issuename
     */
    public String getIssuename() {
    return issuename;
    } /**
     * @param issuename the issuename to set
     */
    public void setIssuename(String issuename) {
    this.issuename = issuename;
    } /**
     * @return the issuetime
     */
    public String getIssuetime() {
    return issuetime;
    } /**
     * @param issuetime the issuetime to set
     */
    public void setIssuetime(String issuetime) {
    this.issuetime = issuetime;
    } /**
     * @return the picture
     */
    public String getPicture() {
    return picture;
    } /**
     * @param picture the picture to set
     */
    public void setPicture(String picture) {
    this.picture = picture;
    } /**
     * @return the topic
     */
    public String getTopic() {
    return topic;
    } /**
     * @param topic the topic to set
     */
    public void setTopic(String topic) {
    this.topic = topic;
    }
    }
    /**  DAO类 **/
    package com.lhzx.db;import java.sql.PreparedStatement;
    import java.util.ArrayList;public class NewsDao { DBConn dbcon = new DBConn();

    /**
     * @deprecated 查询所有的新闻
     * @author 
     * @创建时间 2007-09-26
     * @return list
     */
    public ArrayList<News> findAllNews(){
    try{
    ArrayList<News> list = new ArrayList<News>();
    String sql = "select * from news";
    PreparedStatement ps = dbcon.conn.prepareStatement(sql);
    dbcon.rs = ps.executeQuery();
    while(dbcon.rs.next()){
    News news = new News();
    news.setId(dbcon.rs.getInt("id"));
    news.setContent(dbcon.rs.getString("content"));
    news.setIssuename(dbcon.rs.getString("issuename"));
    news.setIssuetime(dbcon.rs.getString("issuetime"));
    news.setPicture(dbcon.rs.getString("picture"));
    news.setTopic(dbcon.rs.getString("topic"));
    list.add(news);
    }
    return list;
    }catch(Exception e){
    e.printStackTrace();
    return null;
    }
    }
    }
    /**  Action类 **/package com.lx.news.struts.action;import java.util.List;import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;import com.lx.news.db.NewsDao;
    import com.lx.news.struts.form.NewsListForm;/**
     * MyEclipse Struts Creation date: 09-15-2007
     * 
     * XDoclet definition:
     * 
     * @struts.action path="/newsList" name="newsListForm" input="/login.jsp"
     *                scope="request" validate="true"
     */
    public class NewsListAction extends Action {
    /*
     * Generated Methods
     */ /**
     * Method execute
     * 
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return ActionForward
     */
    public ActionForward execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response) {
    NewsListForm newsListForm = (NewsListForm) form;// TODO Auto-generated
    // method stub
    HttpSession session = request.getSession();
    NewsDao newsDao = new NewsDao();
    ArrayList<News> newslist =  newsDao.findAllNews();
                      request.setAttribute("newslist", newslist );
    return mapping.findForward("success");
    }
    }
      

  6.   

    个人意见,如果楼主在别的地方还要用到这个页面,而又不想用session的话,可以用简单的自定义标签啊.