论坛模块_实现功能2_实现显示版块列表与显示单个版块的功能
填充ForumAction类中的方法
页面四个小步骤:1拷贝静态页面,2把公共的Include放进来,自己特殊的样式留下,3改路径,4根据具体内容写代码
forumActionlist/list.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> <title>论坛</title> <%@ include file="/WEB-INF/jsp/public/commons.jspf" %> <link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/style/blue/forum.css" /> <script type="text/javascript"> </script> </head> <body> <div id="Title_bar"> <div id="Title_bar_Head"> <div id="Title_Head"></div> <div id="Title"> <!--页面标题--> <img border="0" width="13" height="13" src="${pageContext.request.contextPath}/style/images/title_arrow.gif"/> 论坛 </div> <div id="Title_End"></div> </div> </div> <div id="MainArea"> <center> <div class="ForumPageTableBorder" style="margin-top: 25px;"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <!--表头--> <tr align="center" valign="middle"> <td colspan="3" class="ForumPageTableTitleLeft">版块</td> <td width="80" class="ForumPageTableTitle">主题数</td> <td width="80" class="ForumPageTableTitle">文章数</td> <td width="270" class="ForumPageTableTitle">最后发表的主题</td> </tr> <tr height="1" class="ForumPageTableTitleLine"><td colspan="9"></td></tr> <tr height="3"><td colspan="9"></td></tr> <!--版面列表--> <tbody class="dataContainer" datakey="forumList"> <s:iterator value="#forumList"> <tr height="78" align="center" class="template"> <td width="3"></td> <td width="75" class="ForumPageTableDataLine"> <img src="${pageContext.request.contextPath}/style/images/forumpage3.gif" /> </td> <td class="ForumPageTableDataLine"> <ul class="ForumPageTopicUl"> <li class="ForumPageTopic"><s:a cssClass="ForumPageTopic" action="forum_show?id=%{id}">${name}</s:a></li> <li class="ForumPageTopicMemo">${description}</li> </ul> </td> <td class="ForumPageTableDataLine"><b>${topicCount}</b></td> <td class="ForumPageTableDataLine"><b>${articleCount}</b></td> <td class="ForumPageTableDataLine"> <ul class="ForumPageTopicUl"> <li><font color="#444444">┌ 主题:</font> <s:a cssClass="ForumTitle" action="topic_show?id=%{lastTopic.id}">${lastTopic.title}</s:a> </li> <li><font color="#444444">├ 作者:</font> ${lastTopic.author.name}</li> <li><font color="#444444">└ 时间:</font> ${lastTopic.postTime}</li> </ul> </td> <td width="3"></td> </tr> </s:iterator> </tbody> <!-- 版面列表结束 --> <tr height="3"><td colspan="9"></td></tr> </table> </div> </center> </div> </body> </html>
启动服务器访问论坛,会报错,原因是在版块中的topicCount和articleCount两字段是null,解决办法,删除全部版块,重新创建
forumActionlist/show.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> <title>【${forum.name}】中的主题列表</title> <%@ include file="/WEB-INF/jsp/public/commons.jspf" %> <link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/style/blue/forum.css" /> </head> <body> <!-- 标题显示 --> <div id="Title_bar"> <div id="Title_bar_Head"> <div id="Title_Head"></div> <div id="Title"><!--页面标题--> <img border="0" width="13" height="13" src="${pageContext.request.contextPath}/style/images/topicType_${type }.gif"/> 【${forum.name}】中的主题列表 </div> <div id="Title_End"></div> </div> </div> <div id="MainArea"> <div id="PageHead"></div> <center> <div class="ItemBlock_Title1" style=" 98%;"> <font class="MenuPoint"> > </font> <s:a action="forum_list">论坛</s:a> <font class="MenuPoint"> > </font> ${forum.name} <span style="margin-left:30px;"> <s:a action="topic_addUI?forumId=%{#forum.id}"> <img align="absmiddle" src="${pageContext.request.contextPath}/style/blue/images/button/publishNewTopic.png"/></s:a> </span> </div> <div class="ForumPageTableBorder"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <!--表头--> <tr align="center" valign="middle"> <td width="3" class="ForumPageTableTitleLeft"> <img border="0" width="1" height="1" src="${pageContext.request.contextPath}/style/images/blank.gif" /> </td> <td width="50" class="ForumPageTableTitle"><!--状态/图标--> </td> <td class="ForumPageTableTitle">主题</td> <td width="130" class="ForumPageTableTitle">作者</td> <td width="100" class="ForumPageTableTitle">回复数</td> <td width="130" class="ForumPageTableTitle">最后回复</td> <td width="3" class="ForumPageTableTitleRight"> <img border="0" width="1" height="1" src="${pageContext.request.contextPath}/style/images/blank.gif" /> </td> </tr> <tr height="1" class="ForumPageTableTitleLine"><td colspan="8"></td></tr> <tr height=3><td colspan=8></td></tr> <!--主题列表--> <tbody class="dataContainer" datakey="topicList"> <s:iterator value="#topicList"> <tr height="35" id="d0" class="template"> <td></td> <td class="ForumTopicPageDataLine" align="center"><img src="${pageContext.request.contextPath}/style/images/topicType_${type}.gif" /></td> <td class="Topic"> <s:a cssClass="Default" action="topic_show?id=%{id}">${title}</s:a></td> <td class="ForumTopicPageDataLine"> <ul class="ForumPageTopicUl"> <li class="Author">${author.name}</li> <li class="CreateTime">${postTime}</li> </ul> </td> <td class="ForumTopicPageDataLine Reply" align="center"><b>${replyCount}</b></td> <td class="ForumTopicPageDataLine"> <ul class="ForumPageTopicUl"> <li class="Author">${lastReply.author.name}</li> <li class="CreateTime">${lastReply.postTime}</li> </ul> </td> <td></td> </tr> </s:iterator> </tbody> <!--主题列表结束--> <tr height="3"><td colspan="9"></td></tr> </table> <!--其他操作--> <div id="TableTail"> <div id="TableTail_inside"> <table border="0" cellspacing="0" cellpadding="0" height="100%" align="left"> <tr valign=bottom> <td></td> <td><select name="viewType"> <option value="0">全部主题</option> <option value="1">全部精华贴</option> <!-- <option value="2">当天的主题</option> <option value="3">本周的主题</option> <option value="4">本月的主题</option> --> </select> <select name="orderBy"> <option value="0">默认排序(按最后更新时间排序,但所有置顶帖都在前面)</option> <option value="1">按最后更新时间排序</option> <option value="2">按主题发表时间排序</option> <option value="3">按回复数量排序</option> </select> <select name="reverse"> <option value="true">降序</option> <option value="false">升序</option> </select> <input type="IMAGE" src="${pageContext.request.contextPath}/style/blue/images/button/submit.PNG" align="ABSMIDDLE"/> </td> </tr> </table> </div> </div> </div> </center> </div> <!--分页信息--> <div id=PageSelectorBar> <div id=PageSelectorMemo> 页次:7/13页 每页显示:30条 总记录数:385条 </div> <div id=PageSelectorSelectorArea> <!-- <IMG SRC="${pageContext.request.contextPath}/style/blue/images/pageSelector/firstPage2.png"/> --> <a href="javascript:void(0)" title="首页" style="cursor: hand;"> <img src="${pageContext.request.contextPath}/style/blue/images/pageSelector/firstPage.png"/></a> <span class="PageSelectorNum" style="cursor: hand;" onClick="gotoPageNum(2);">3</span> <span class="PageSelectorNum" style="cursor: hand;" onClick="gotoPageNum(2);">4</span> <span class="PageSelectorNum" style="cursor: hand;" onClick="gotoPageNum(2);">5</span> <span class="PageSelectorNum" style="cursor: hand;" onClick="gotoPageNum(2);">6</span> <span class="PageSelectorNum PageSelectorSelected">7</span> <span class="PageSelectorNum" style="cursor: hand;" onClick="gotoPageNum(2);">8</span> <span class="PageSelectorNum" style="cursor: hand;" onClick="gotoPageNum(2);">9</span> <span class="PageSelectorNum" style="cursor: hand;" onClick="gotoPageNum(2);">10</span> <span class="PageSelectorNum" style="cursor: hand;" onClick="gotoPageNum(2);">11</span> <span class="PageSelectorNum" style="cursor: hand;" onClick="gotoPageNum(2);">12</span> <!-- <IMG SRC="${pageContext.request.contextPath}/style/blue/images/pageSelector/lastPage2.png"/> --> <a href="#" title="尾页" style="cursor: hand;"> <img src="${pageContext.request.contextPath}/style/blue/images/pageSelector/lastPage.png"/></a> 转到: <input onFocus="this.select();" maxlength="2" class="inputStyle" type="text" value="1" name="currPage" tabindex="0"/> <input type="submit" name="goBtn" value="Go" class="MiddleButtonStyle" /> </div> </div> <div class="Description"> 说明:<br /> 1,主题默认按最后更新的时间降序排列。最后更新时间是指主题最后回复的时间,如果没有回复,就是主题发表的时间。<br /> 2,帖子有普通、置顶、精华之分。置顶贴始终显示在最上面,精华贴用不同的图标标示。<br /> </div> </body> </html>
在TopicAction.java中添加字段
ForumAction.java中填写代码