我正在做JSP/SERVLET论坛程序,很想采用这个论坛的方式,就是不愿写XSL,这是首页源码。不知道YYSUN有无兴趣看一下.(100分)

  • 主题发起人 xiaoboliu
  • 开始时间
X

xiaoboliu

Unregistered / Unconfirmed
GUEST, unregistred user!

Iterator模式的例子-JustForum2首页源代码
来自:LiuXiaobo /1292.net 日期:2001-11-27 人气:4
为保持页面显示和业务逻辑分离,JF2采用model2方式(m=beans,v=jsp,c=Servlet)应用Iterator模式.

Iterator模式的具体解释,去看<设计模式>。
下面是一个bean内的方法
public Iterator getForums() {
Vector vector=null;
try{
vector=new Vector();
ResultSet rs=executeSelect("SELECT * FROM justForum ORDER BY forumID");
while (rs.next()){
JFForum forum=new JFForum();
forum.setForumID(rs.getString("forumID"));
forum.setForumName(rs.getString("forumName"));
forum.setForumDescription(rs.getString("forumDescription"));
forum.setThreadCount(rs.getString("threadCount"));
forum.setMessageCount(rs.getString("messageCount"));
forum.setLastReTime(rs.getString("lastReTime"));
forum.setLastReUserName(rs.getString("lastReUserName"));
forum.setForumMasterName(rs.getString("forumMasterName"));
vector.add(forum);
count++;
}
rs.close();
closeSelect();
} catch (SQLException sqle) {
System.out.println("Error: " + sqle);
}finally{
//close();
}
return vector.iterator();
}

下面是一个Servlet内的方法
public voiddo
Get(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException {
try {
java.util.Iterator forums = (new JFForumDBAccess()).getForums();
request.setAttribute("Forums", forums);
_callPage("/index.jsp",request,response);
} catch (Exception e) {
request.setAttribute("JFE", e);
_callPage("/error.jsp",request,response);
}
}
下面是一个JSP页面部份内容
<%
Iterator forumIterator = (Iterator)request.getAttribute("Forums");
while( forumIterator.hasNext() ) {
JFForum forum = (JFForum)forumIterator.next();
String forumID=forum.getForumID();
String forumName=forum.getForumName();
String forumDescription=forum.getForumDescription();
String threadCount =forum.getThreadCount() ;
String messageCount=forum.getMessageCount() ;
String lastReTime= forum.getLastReTime();
String lastReUserName=forum.getLastReUserName();
String forumMasterName=forum.getForumMasterName();
%>
<tr>
<td class="td_b">
&amp;nbsp;
</td>
<td class="td_b">
<a href="./forum.jsp?forumID=<%= forumID %>"><%=forumName %></a><br>
<%= forumDescription%><br>
</td>
<td class="td_b">
<%=threadCount %>/<%= messageCount %>
</td>
<td class="td_b"><%=lastReTime %><br>
<a href="./profile.jsp?userName=<%=java.net.URLEncoder.encode(lastReUserName)%>"> <%=lastReUserName%></a>
</td>
<td class="td_b">
<a href="./profile.jsp?userName=<%=java.net.URLEncoder.encode(forumMasterName)%>"> <%=forumMasterName%></a>
</td>
</tr>
<%
}
%>
 
顶部