TopicAction.java
上传用户:jishiqi_cj
上传日期:2022-08-08
资源大小:24765k
文件大小:3k
源码类别:

Java编程

开发平台:

Java

  1. /*
  2. /*主题
  3. */
  4. package StudyBbs;
  5. import javax.servlet.http.HttpServletRequest;
  6. import javax.servlet.http.HttpServletResponse;
  7. import javax.servlet.http.HttpSession;
  8. import org.apache.struts.action.Action;
  9. import org.apache.struts.action.ActionForm;
  10. import org.apache.struts.action.ActionForward;
  11. import org.apache.struts.action.ActionMapping;
  12. import org.apache.struts.action.ActionMessage;
  13. import org.apache.struts.action.ActionMessages;
  14. import javax.servlet.ServletContext;
  15. import javax.sql.DataSource;
  16. import java.sql.Connection;
  17. import java.util.Vector;
  18. public final class TopicAction extends Action{  
  19. public ActionForward execute(
  20. ActionMapping mapping,
  21. ActionForm form,
  22. HttpServletRequest request,  
  23. HttpServletResponse response) throws Exception {
  24.     SortForm sortform = (SortForm) form; 
  25.             
  26. int sortid = sortform.getSortid();
  27. String sortname = sortform.getSortname();
  28. int pageid = sortform.getPageid();
  29. if (pageid<0){
  30. pageid = 0;
  31. }
  32.         HttpSession session = request.getSession(true);
  33. Vector topics = new Vector();
  34. Topic topic;
  35.     ServletContext context = servlet.getServletContext();
  36. DataSource dataSource = 
  37. (DataSource)context.getAttribute(Constants.DATASOURCE_KEY);
  38.         DB db = new DB(dataSource);
  39.         TopicDisp topicdisp = new TopicDisp();
  40.         
  41. String PageForward;
  42. ActionMessages errors = new ActionMessages();
  43.         if (topicdisp.GetTopicCount(db,sortid)==0){
  44. session.setAttribute(Constants.TOPIC_LIST_KEY,topics);
  45. // session.setAttribute(Constants.TALK_TYPE_KEY,"topic");
  46. session.setAttribute(Constants.CUR_SORTID_KEY,new Integer(sortid));
  47. session.setAttribute(Constants.CUR_SORTNAME_KEY,sortname);
  48. session.setAttribute(Constants.CUR_PAGEID_KEY,new Integer(pageid));
  49.    PageForward="toTopic";  
  50.         }
  51.         else if (topicdisp.GetTopicCount(db,sortid)<pageid * Constants.TOPIC_PAGE_SIZE + 1){
  52.          pageid--;
  53.             errors.add(ActionMessages.GLOBAL_MESSAGE,
  54.                            new ActionMessage("errors.pageEnd"));
  55. if (!errors.isEmpty()) {
  56. saveErrors(request, errors);
  57.   PageForward="toWrong";  
  58. }
  59. else{
  60.          topicdisp.setSortid(sortid);
  61. topics = topicdisp.search(db,pageid);
  62. session.setAttribute(Constants.TOPIC_LIST_KEY,topics);
  63. // session.setAttribute(Constants.TALK_TYPE_KEY,"topic");
  64. session.setAttribute(Constants.CUR_SORTID_KEY,new Integer(sortid));
  65. session.setAttribute(Constants.CUR_SORTNAME_KEY,sortname);
  66. session.setAttribute(Constants.CUR_PAGEID_KEY,new Integer(pageid));
  67.    PageForward="toTopic";  
  68.        }
  69. db.close();
  70.     return (mapping.findForward(PageForward));
  71.   }
  72. }