📄 articleaction.java
字号:
if (searchForm.getCondition() == null || searchForm.getCondition() == null) condition = ""; else condition = "where articletitle like '%" + searchForm.getCondition() + "%' or articlecontent like '%" + searchForm.getCondition() + "%'"; } session.setAttribute("CONDITION", condition); } else { offset = Integer.parseInt(pageOffset); condition = (String) session.getAttribute("CONDITION"); if (condition == null) { condition = ""; } } List articlelist = (List) articleDAO.list(offset, length, condition); int size = articleDAO.getSize("article", condition); String url = request.getContextPath() + mapping.getPath() + ".do"; String pagerHeader = math.util.Pager.generate(offset, size, length, url); request.setAttribute("pagerHeader", pagerHeader); request.setAttribute("LIST", articlelist); request.setAttribute("articletype1", articlelist); return mapping.findForward("success"); } } // ����Ϊ��̨�����б� catch (Exception e) { generalError(request, e); return mapping.findForward("failure"); } } // ////////////////////////////////////////////////////////////// private ActionForward performShow(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { try { HttpSession session = request.getSession(); ArticleDAO articleDAO = new ArticleDAO(ds); int id = 0; String str_id = request.getParameter("articleid"); if (str_id != null && !str_id.equals("")) { id = Integer.parseInt(str_id); } else { return mapping.findForward("error"); } // ʵ��Reg; Article article = articleDAO.select(id); // ��Reg�е�ֵ����regForm int count = article.getArticlecount() + 1; articleDAO.retrive(count, id); session.setAttribute("Article", article); // ��reg��Ϊ�����RegDAO�е�insert���� return mapping.findForward("success"); } catch (Exception e) { generalError(request, e); return mapping.findForward("failure"); } } // /////////////////////////////////////////////////// private ActionForward performUpdate(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { try { // HttpSession session = request.getSession() ; ArticleDAO articleDAO = new ArticleDAO(ds); ArticleForm articleForm = (ArticleForm) actionForm; int id = 0; String str_id = request.getParameter("articleid"); if (str_id != null && !str_id.equals("")) { id = Integer.parseInt(str_id); } else { return mapping.findForward("error"); } // ʵ��Reg; Article article = articleDAO.select(id); // ��Reg�е�ֵ����regForm BeanUtils.populate(articleForm, BeanUtils.describe(article)); request.setAttribute("Article", article); request.setAttribute("articletype2", String.valueOf(article .getArticletype2())); request.setAttribute("articletype1", String.valueOf(article .getArticletype1())); // ��reg��Ϊ�����RegDAO�е�insert���� return mapping.findForward("success"); } catch (Exception e) { generalError(request, e); return mapping.findForward("failure"); } } // ///////////////////////////////////////////////////////////////// private ActionForward performSave(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { try { ArticleDAO articleDAO = new ArticleDAO(ds); // ��ñ?��Ϣ ArticleForm articleForm = (ArticleForm) actionForm; // ʵ��Reg; if (actionForm instanceof ArticleForm) { ds = getDataSource(request); String encoding = request.getCharacterEncoding(); if ((encoding != null) && (encoding.equalsIgnoreCase("GB2312"))) { response.setContentType("text/html;charset=GB2312"); } String Dir = "../webapps" + request.getContextPath() + "/article_download"; File dirName = new File(Dir); if (!dirName.exists()) { dirName.mkdirs(); } String pic_path = ""; String gs = articleForm.getGs(); Date mydate = new Date(); long picname = (long) mydate.getTime(); if (articleForm.getTheFile().getFileName() == null || articleForm.getTheFile().getFileName() .equalsIgnoreCase("")) { pic_path = ""; } else { pic_path = "article_download/" + picname + gs; } Article article = new Article(); // ��RegForm�е�ֵ����reg BeanUtils.populate(article, BeanUtils.describe(articleForm)); article.setArticle_img(pic_path); article.setUserip(request.getRemoteHost()); articleDAO.update(article); FormFile file = articleForm.getTheFile(); try { if (!articleForm.getTheFile().getFileName() .equalsIgnoreCase("")) { InputStream stream = file.getInputStream(); OutputStream bos = new FileOutputStream(Dir + "/" + picname + gs); int bytesRead = 0; byte[] buffer = new byte[8192]; while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) { bos.write(buffer, 0, bytesRead); } bos.close(); // close the stream stream.close(); } } catch (FileNotFoundException fnfe) { return null; } catch (IOException ioe) { return null; } // destroy the temporary file created file.destroy(); return mapping.findForward("success"); // HttpSession session = request.getSession(); // session.setAttribute("REG", reg); } return mapping.findForward("failure"); } catch (Exception e) { generalError(request, e); return mapping.findForward("failure"); } } // ///////////////////////////////////////////////////////////////////// private ActionForward performDelete(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { try { int id = 0; String str_id = request.getParameter("articleid"); if (str_id != null && !str_id.equals("")) { id = Integer.parseInt(str_id); } else { return mapping.findForward("error"); } ArticleDAO articleDAO = new ArticleDAO(ds); ArticleForm articleForm = (ArticleForm) actionForm; // ʵ��Reg; Article article = new Article(); // ��RegForm�е�ֵ����reg BeanUtils.populate(article, BeanUtils.describe(articleForm)); // String username = regForm.getUsers_name(); // ��reg��Ϊ�����RegDAO�е�insert���� article.setArticleid(id); articleDAO.delete(article); return mapping.findForward("success"); } catch (Exception e) { generalError(request, e); return mapping.findForward("failure"); } } // ///////////////////////////////////////////////////////////// private void sqlNullError(HttpServletRequest request, int result) { ActionErrors errors = new ActionErrors(); if (result == 1) { errors.add("reg", new ActionError("error.reg.exist")); } if (result == 2) { errors.add("wrong", new ActionError("error.reg.pass")); } if (result == 3) { errors.add("relogin", new ActionError("error.reg.relogin")); } saveErrors(request, errors); if (__log.isErrorEnabled()) { __log.error(" [Reg] has not found - " + result); } } private void generalError(HttpServletRequest request, Exception e) { ActionErrors aes = new ActionErrors(); aes.add(aes.GLOBAL_ERROR, new ActionError("error.general", e .getMessage())); saveErrors(request, aes); e.printStackTrace(); if (__log.isErrorEnabled()) { __log.error(" [Reg] Error - " + e.getMessage()); } } // TODO Auto-generated method stub}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -