コード例 #1
0
 // 处理事务:开启新闻或是关闭新闻,不使用ActionForm,主键通过URL由HttpServletRequest对象获取
 public ActionForward setIsUsed(
     ActionMapping mapping,
     ActionForm actionForm,
     HttpServletRequest request,
     HttpServletResponse response)
     throws Exception {
   int num = Integer.parseInt(request.getParameter(Name.Property));
   String hql = "from News news where news.num='" + num + "'";
   News news = Controller.get(hql);
   String code = request.getParameter("code");
   if ("start".equals(code)) {
     news.setIsUsed(true);
   } else {
     news.setIsUsed(false);
   }
   Controller.update(news);
   response.sendRedirect("news_view.do?method=viewList");
   return null;
 }
コード例 #2
0
  // 处理事务:更新新闻
  public ActionForward update(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    DynaActionForm form = (DynaActionForm) actionForm;
    HttpSession session = request.getSession();
    News news = (News) session.getAttribute(Name.AdminNews);
    session.removeAttribute(Name.AdminNews);

    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");

    news.setTitle(title);
    news.setCategoryNum(categoryNum);
    news.setDetail(detail);
    String successStr;
    if (Controller.update(news)) {
      successStr = "成功更新资讯 " + title + "<br/>\n";
      successStr +=
          "<a href=\"news-select.do?method=updateView&property="
              + news.getNum()
              + "\">重新修改</a><br/>\n";
    } else {
      successStr = "更新 " + title + "失败,<br/>\n";
      successStr +=
          "<a href=\"news-select.do?method=updateView&property="
              + news.getNum()
              + "\">重试</a><br/>\n";
    }

    successStr += "<a href=\"news_view.do?method=viewList\">返回资讯列表</a>";
    session.setAttribute(Name.AdminSuccessInfo, successStr);
    return mapping.findForward("success");
  }