IndexAction.java
上传用户:yunfeng252
上传日期:2022-07-23
资源大小:12403k
文件大小:2k
- package org.yufeng.struts.action;
- import java.util.List;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
- import org.apache.struts.action.ActionForm;
- import org.apache.struts.action.ActionForward;
- import org.apache.struts.action.ActionMapping;
- import org.yufeng.domains.Article;
- import org.yufeng.domains.Assort;
- import org.yufeng.domains.Sort;
- import org.yufeng.service.ISortServiceDao;
- import org.yufeng.utils.*;
- public class IndexAction extends BaseAction {
- public ActionForward index_show(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- HttpSession session = request.getSession();
- try {
- //获得Sort信息
- ISortServiceDao sortService = (ISortServiceDao)this.getSortService();
- List sort_list = sortService.browseSort();
- Sort sort = null;
- int so_allcount = 0; //记录文章的总数
- for(int i=0;i<sort_list.size();i++){
- sort = (Sort)sort_list.get(i);
- List<Article> article_list = getArticleService().browseArticleBySo_id_index(sort.getSo_id());
- so_allcount = so_allcount + article_list.size();
- Article article = null;
- //获得所有Article信息
- sort.setSo_count(article_list.size());
- for(int j=0;j<article_list.size();j++){
- article =(Article)article_list.get(j);
- List assort_list = this.getAssortService().browseAssortById(article.getAr_assort_id());
- Assort assort = (Assort)assort_list.get(0);
- //封装Article的Assort
- article.setAr_assort_name(assort.getAs_name());
- //修改时间的显示
- article.setAr_createTime(Tools.getDataByMD(article.getAr_createTime()));
- }
- sort.setArticle_list(article_list);
- }
- //获得阅读排行信息
- List ar_hits_list = getArticleService().browseArticleByHits();
- //获得主页推荐信息
- List ar_show_list = getArticleService().browseArticleByShow();
- List link_list = this.getlinkService().browseLink();
- session.setAttribute("link_list", link_list);
- //防止访问出错
- session.removeAttribute("ar_hits_list");
- session.removeAttribute("assort_list");
-
- session.setAttribute("so_allcount",so_allcount);
- session.setAttribute("sort_list", sort_list);
- session.setAttribute("ar_hits_list", ar_hits_list);
- session.setAttribute("ar_show_list", ar_show_list);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return mapping.findForward("index_show");
- }
- }