FolderAction.java
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:6k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. //Created by MyEclipse Struts
  2. // XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.1.0/xslt/JavaClass.xsl
  3. package com.oa.module.folder.action;
  4. import java.io.File;
  5. import java.io.IOException;
  6. import java.io.PrintWriter;
  7. import java.util.List;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.servlet.http.HttpServletResponse;
  10. import javax.servlet.http.HttpSession;
  11. import org.apache.struts.action.ActionForm;
  12. import org.apache.struts.action.ActionForward;
  13. import org.apache.struts.action.ActionMapping;
  14. import org.apache.struts.actions.DispatchAction;
  15. import com.oa.module.folder.Forder;
  16. import com.oa.module.folder.bean.FolderBean;
  17. import com.oa.module.folder.dao.FileDao;
  18. import com.oa.module.folder.dao.FolderDao;
  19. import com.oa.module.folder.form.FolderForm;
  20. import com.oa.module.office.user.Tuser;
  21. /**文件夹处理ACTION
  22.  * MyEclipse Struts Creation date: 01-28-2008
  23.  * 
  24.  * XDoclet definition:
  25.  * 
  26.  * @struts.action path="/folder" name="folderForm" parameter="method"
  27.  *                scope="request" validate="true"
  28.  */
  29. public class FolderAction extends DispatchAction {
  30. // --------------------------------------------------------- Instance
  31. private FolderDao dao;
  32. private FileDao filedao;
  33. private Forder forder;
  34. // Variables
  35. // --------------------------------------------------------- Methods
  36. public Forder getForder() {
  37. return forder;
  38. }
  39. public void setForder(Forder forder) {
  40. this.forder = forder;
  41. }
  42. /**
  43.  * Method execute 获取我的文件夹
  44.  * 
  45.  * @param mapping
  46.  * @param form
  47.  * @param request
  48.  * @param response
  49.  * @return ActionForward
  50.  */
  51. public ActionForward myFolder(ActionMapping mapping, ActionForm form,
  52. HttpServletRequest request, HttpServletResponse response) {
  53. FolderForm folderForm = (FolderForm) form;
  54. HttpSession session = request.getSession();
  55. Tuser user = (Tuser) session.getAttribute("user");
  56. String id = user.getUno();
  57. List list = dao.getUserFolder(id);
  58. request.setAttribute("myFolderList", list);
  59. return mapping.findForward("myforder");
  60. }
  61. /**
  62.  * 创建新的文件夹
  63.  * 
  64.  * @param mapping
  65.  * @param form
  66.  * @param request
  67.  * @param response
  68.  * @return
  69.  */
  70. public ActionForward newforder(ActionMapping mapping, ActionForm form,
  71. HttpServletRequest request, HttpServletResponse response) {
  72. FolderForm folderForm = (FolderForm) form;
  73. String fordername = request.getParameter("fordername");
  74. HttpSession session = request.getSession();
  75. Tuser user = (Tuser) session.getAttribute("user");
  76. String id = user.getUno();
  77. String name = user.getUname();
  78. String path = this.getServlet().getServletContext().getRealPath("/");
  79. path = path.replace('\', '/');
  80. path += "forder";
  81. boolean flag = forder.buildUserForder(id, name, fordername,path);
  82. if(flag ==true){
  83. //成功
  84. request.setAttribute("task","builduserfordersuc");
  85. return mapping.findForward("suc");
  86. }else{
  87. request.setAttribute("task","builduserfordererror");
  88. return mapping.findForward("error");
  89. }
  90. }
  91. /**
  92.  * 修改文件夹
  93.  * @param mapping
  94.  * @param form
  95.  * @param request
  96.  * @param response
  97.  * @return
  98.  */
  99. public ActionForward xiugaiforder(ActionMapping mapping, ActionForm form,
  100. HttpServletRequest request, HttpServletResponse response) {
  101. FolderForm folderForm = (FolderForm) form;
  102. String fordername = request.getParameter("fordername");
  103. String forderid = request.getParameter("forderid");
  104. //是否存在
  105. boolean flag  = dao.isExist(forderid, fordername);
  106. if(flag == true){
  107. try {
  108. PrintWriter out = response.getWriter();
  109. out.print("<script>");
  110. out.print("alert('对不起文件夹名字已经存在()');");
  111. out.print("history.back();");
  112. out.print("</script>");
  113. return null;
  114. } catch (IOException e) {
  115. // TODO 自动生成 catch 块
  116. e.printStackTrace();
  117. }
  118. }
  119.  flag = dao.uploadForder(forderid, fordername);
  120.  if(flag ==true){
  121. //成功
  122. request.setAttribute("task","xiugaisuc");
  123. return mapping.findForward("suc");
  124. }else{
  125. request.setAttribute("task","xiugaierror");
  126. return mapping.findForward("error");
  127. }
  128. }
  129. /**
  130.  * 删除文件夹
  131.  * @param mapping
  132.  * @param form
  133.  * @param request
  134.  * @param response
  135.  * @return
  136.  */
  137. public ActionForward deleteFolder(ActionMapping mapping, ActionForm form,
  138. HttpServletRequest request, HttpServletResponse response) {
  139. FolderForm folderForm = (FolderForm) form;
  140. String forderid = request.getParameter("forderid");
  141. // 目录删除
  142. FolderBean  bean = dao.getForderByForderId(forderid);
  143. String path = this.getServlet().getServletContext().getRealPath("/");
  144. path = path.replace('\','/');
  145. path += "forder";
  146. HttpSession session = request.getSession();
  147. Tuser user = (Tuser)session.getAttribute("user");
  148. String filename= path+"/"+user.getUname()+","+user.getUno()+"/"+bean.getFordername();
  149. File file  = new File(filename);
  150. File[] filelist = file.listFiles();
  151. //把所有文件删除了
  152. for(int i = 0 ; i<filelist.length; i++){
  153. filelist[i].delete();
  154. }
  155. //目录删除
  156. file.delete();
  157. //文件夹表删除
  158. boolean flag = dao.delForder(forderid);
  159. //文件表记录删除
  160. flag  = dao.delFileByForderId(forderid);
  161. if(flag ==true){
  162. //成功
  163. request.setAttribute("task","delsuc");
  164. return mapping.findForward("suc");
  165. }else{
  166. request.setAttribute("task","delrror");
  167. return mapping.findForward("error");
  168. }
  169. }
  170. /**
  171.  * 上传文件
  172.  * @param mapping
  173.  * @param form
  174.  * @param request
  175.  * @param response
  176.  * @return
  177.  */
  178. public ActionForward uploadfile(ActionMapping mapping, ActionForm form,
  179. HttpServletRequest request, HttpServletResponse response) {
  180. FolderForm folderForm = (FolderForm) form;
  181. return null;
  182. }
  183. public FolderDao getDao() {
  184. return dao;
  185. }
  186. public void setDao(FolderDao dao) {
  187. this.dao = dao;
  188. }
  189. public FileDao getFiledao() {
  190. return filedao;
  191. }
  192. public void setFiledao(FileDao filedao) {
  193. this.filedao = filedao;
  194. }
  195. }