TopicAction.java
上传用户:jishiqi_cj
上传日期:2022-08-08
资源大小:24765k
文件大小:3k
- /*
- /*主题
- */
- package StudyBbs;
- 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 org.apache.struts.action.ActionMessage;
- import org.apache.struts.action.ActionMessages;
- import javax.servlet.ServletContext;
- import javax.sql.DataSource;
- import java.sql.Connection;
- import java.util.Vector;
- public final class TopicAction extends Action{
- public ActionForward execute(
- ActionMapping mapping,
- ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response) throws Exception {
-
- SortForm sortform = (SortForm) form;
-
- int sortid = sortform.getSortid();
- String sortname = sortform.getSortname();
- int pageid = sortform.getPageid();
- if (pageid<0){
- pageid = 0;
- }
-
- HttpSession session = request.getSession(true);
- Vector topics = new Vector();
- Topic topic;
-
- ServletContext context = servlet.getServletContext();
- DataSource dataSource =
- (DataSource)context.getAttribute(Constants.DATASOURCE_KEY);
-
- DB db = new DB(dataSource);
- TopicDisp topicdisp = new TopicDisp();
-
- String PageForward;
- ActionMessages errors = new ActionMessages();
- if (topicdisp.GetTopicCount(db,sortid)==0){
- session.setAttribute(Constants.TOPIC_LIST_KEY,topics);
- // session.setAttribute(Constants.TALK_TYPE_KEY,"topic");
- session.setAttribute(Constants.CUR_SORTID_KEY,new Integer(sortid));
- session.setAttribute(Constants.CUR_SORTNAME_KEY,sortname);
- session.setAttribute(Constants.CUR_PAGEID_KEY,new Integer(pageid));
- PageForward="toTopic";
- }
- else if (topicdisp.GetTopicCount(db,sortid)<pageid * Constants.TOPIC_PAGE_SIZE + 1){
- pageid--;
- errors.add(ActionMessages.GLOBAL_MESSAGE,
- new ActionMessage("errors.pageEnd"));
- if (!errors.isEmpty()) {
- saveErrors(request, errors);
- }
- PageForward="toWrong";
- }
- else{
- topicdisp.setSortid(sortid);
- topics = topicdisp.search(db,pageid);
- session.setAttribute(Constants.TOPIC_LIST_KEY,topics);
- // session.setAttribute(Constants.TALK_TYPE_KEY,"topic");
- session.setAttribute(Constants.CUR_SORTID_KEY,new Integer(sortid));
- session.setAttribute(Constants.CUR_SORTNAME_KEY,sortname);
- session.setAttribute(Constants.CUR_PAGEID_KEY,new Integer(pageid));
- PageForward="toTopic";
- }
-
- db.close();
- return (mapping.findForward(PageForward));
- }
- }