Пример #1
0
  // 处理事务:新增新闻
  public ActionForward add(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    DynaActionForm form = (DynaActionForm) actionForm;
    HttpSession session = request.getSession();
    int categoryNum = (Integer) form.get("categoryNum");
    String title = form.getString("title");
    String detail = form.getString("editorContent");
    title = new String(title.getBytes("iso-8859-1"), "utf-8");
    detail = new String(detail.getBytes("iso-8859-1"), "utf-8");

    Admin admin = (Admin) session.getAttribute(Name.Admin);

    News news = new News();
    news.setAdminNum(admin.getNum());
    news.setTitle(title);
    news.setCategoryNum(categoryNum);
    news.setDetail(detail);
    news.setIsUsed(true);
    Controller.save(news);

    String successStr = "成功添加 " + title + "<br/>\n";
    successStr += "<a href=\"news_add.jsp\">继续添加</a><br/>\n";
    successStr += "<a href=\"news_view.do?method=viewList\">返回资讯列表</a>";

    request.getSession().setAttribute(Name.AdminSuccessInfo, successStr);
    return mapping.findForward("success");
  }
Пример #2
0
  // 初始化新闻列表页面
  public ActionForward viewList(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    HttpSession session = request.getSession();

    String newsHql = "from News news";
    List<News> newsList = Controller.getList(newsHql);

    List<NewsListView> list = new ArrayList<NewsListView>();
    Iterator<News> iter = newsList.iterator();
    News news = null;
    NewsListView nlv = null;
    while (iter.hasNext()) {
      news = iter.next();
      nlv = new NewsListView();
      nlv.setIsUsed(news.getIsUsed());
      nlv.setNum(news.getNum());
      nlv.setTitle(news.getTitle());

      int categoryNum = news.getCategoryNum();
      String categoryName = Page.getNewsCategoryName(categoryNum);
      nlv.setCategoryName(categoryName);

      int adminNum = news.getAdminNum();
      String author = Admin.getAdminName(adminNum);
      nlv.setAuthor(author);

      Timestamp time = news.getTime();
      String date;
      if (time == null) {
        date = "暂无";
      } else {
        date = time.toString();
      }
      nlv.setDate(date);

      list.add(nlv);
    }
    session.setAttribute(Name.AdminNewsList, list);
    return mapping.findForward("success");
  }