📄 topiclistaction.java
字号:
package j2eebbs.user.action;
import j2eebbs.Constants;
import j2eebbs.DB;
import j2eebbs.user.form.ForumForm;
import j2eebbs.TopicDisp;
import java.util.Vector;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.sql.DataSource;
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 org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
public final class TopicListAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ForumForm forumForm = (ForumForm) form;
int forumid = forumForm.getForumid();
String forumname = forumForm.getForumname();
int pageid = forumForm.getPageid();
if (pageid < 0) {
pageid = 0;
}
HttpSession session = request.getSession(true);
Vector topicVector = new Vector();
TopicDisp topicdisp = new TopicDisp();
ActionMessages errors = new ActionMessages();
String pageForward;
ServletContext context = servlet.getServletContext();
DataSource dataSource = (DataSource) context.getAttribute("bbsDB");
DB db = new DB(dataSource);
// 如果指定论坛的主题数为0
if (topicdisp.getTopicCount(db, forumid) == 0) {
session.setAttribute(Constants.TOPIC_LIST_KEY, topicVector);
session.setAttribute(Constants.CUR_FORUMID_KEY,
new Integer(forumid));
session.setAttribute(Constants.CUR_FORUMNAME_KEY, forumname);
session.setAttribute(Constants.CUR_PAGEID_KEY, new Integer(pageid));
pageForward = "ToTopicList";
// 如果到了尾页(比如说每页5条,共10条,现在到了第2页,pageid为1,
// 后翻的话变为2,则10<11,符合此条件。若共有11条,11<11为false)
} else if (topicdisp.getTopicCount(db, forumid) < pageid
* Constants.TOPIC_PAGE_SIZE + 1) {
pageid--;
errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
"error.topiclist.nomorepage"));
if (!errors.isEmpty()) {
saveErrors(request, errors);
}
pageForward = "ToErrorPage";
// 如果主题数不为0,则搜索出指定论坛中指定页数的主题。
} else {
topicdisp.setForumid(forumid);
topicVector = topicdisp.search(db, pageid);
session.setAttribute(Constants.TOPIC_LIST_KEY, topicVector);
session.setAttribute(Constants.CUR_FORUMID_KEY,
new Integer(forumid));
session.setAttribute(Constants.CUR_FORUMNAME_KEY, forumname);
session.setAttribute(Constants.CUR_PAGEID_KEY, new Integer(pageid));
pageForward = "ToTopicList";
}
db.close();
return (mapping.findForward(pageForward));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -