FolderAction.java
资源名称:(J2EE)oa.rar [点击查看]
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:6k
源码类别:
Jsp/Servlet
开发平台:
Java
- //Created by MyEclipse Struts
- // XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.1.0/xslt/JavaClass.xsl
- package com.oa.module.folder.action;
- import java.io.File;
- import java.io.IOException;
- import java.io.PrintWriter;
- 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.apache.struts.actions.DispatchAction;
- import com.oa.module.folder.Forder;
- import com.oa.module.folder.bean.FolderBean;
- import com.oa.module.folder.dao.FileDao;
- import com.oa.module.folder.dao.FolderDao;
- import com.oa.module.folder.form.FolderForm;
- import com.oa.module.office.user.Tuser;
- /**文件夹处理ACTION
- * MyEclipse Struts Creation date: 01-28-2008
- *
- * XDoclet definition:
- *
- * @struts.action path="/folder" name="folderForm" parameter="method"
- * scope="request" validate="true"
- */
- public class FolderAction extends DispatchAction {
- // --------------------------------------------------------- Instance
- private FolderDao dao;
- private FileDao filedao;
- private Forder forder;
- // Variables
- // --------------------------------------------------------- Methods
- public Forder getForder() {
- return forder;
- }
- public void setForder(Forder forder) {
- this.forder = forder;
- }
- /**
- * Method execute 获取我的文件夹
- *
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return ActionForward
- */
- public ActionForward myFolder(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- FolderForm folderForm = (FolderForm) form;
- HttpSession session = request.getSession();
- Tuser user = (Tuser) session.getAttribute("user");
- String id = user.getUno();
- List list = dao.getUserFolder(id);
- request.setAttribute("myFolderList", list);
- return mapping.findForward("myforder");
- }
- /**
- * 创建新的文件夹
- *
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward newforder(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- FolderForm folderForm = (FolderForm) form;
- String fordername = request.getParameter("fordername");
- HttpSession session = request.getSession();
- Tuser user = (Tuser) session.getAttribute("user");
- String id = user.getUno();
- String name = user.getUname();
- String path = this.getServlet().getServletContext().getRealPath("/");
- path = path.replace('\', '/');
- path += "forder";
- boolean flag = forder.buildUserForder(id, name, fordername,path);
- if(flag ==true){
- //成功
- request.setAttribute("task","builduserfordersuc");
- return mapping.findForward("suc");
- }else{
- request.setAttribute("task","builduserfordererror");
- return mapping.findForward("error");
- }
- }
- /**
- * 修改文件夹
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward xiugaiforder(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- FolderForm folderForm = (FolderForm) form;
- String fordername = request.getParameter("fordername");
- String forderid = request.getParameter("forderid");
- //是否存在
- boolean flag = dao.isExist(forderid, fordername);
- if(flag == true){
- try {
- PrintWriter out = response.getWriter();
- out.print("<script>");
- out.print("alert('对不起文件夹名字已经存在()');");
- out.print("history.back();");
- out.print("</script>");
- return null;
- } catch (IOException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- }
- flag = dao.uploadForder(forderid, fordername);
- if(flag ==true){
- //成功
- request.setAttribute("task","xiugaisuc");
- return mapping.findForward("suc");
- }else{
- request.setAttribute("task","xiugaierror");
- return mapping.findForward("error");
- }
- }
- /**
- * 删除文件夹
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward deleteFolder(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- FolderForm folderForm = (FolderForm) form;
- String forderid = request.getParameter("forderid");
- // 目录删除
- FolderBean bean = dao.getForderByForderId(forderid);
- String path = this.getServlet().getServletContext().getRealPath("/");
- path = path.replace('\','/');
- path += "forder";
- HttpSession session = request.getSession();
- Tuser user = (Tuser)session.getAttribute("user");
- String filename= path+"/"+user.getUname()+","+user.getUno()+"/"+bean.getFordername();
- File file = new File(filename);
- File[] filelist = file.listFiles();
- //把所有文件删除了
- for(int i = 0 ; i<filelist.length; i++){
- filelist[i].delete();
- }
- //目录删除
- file.delete();
- //文件夹表删除
- boolean flag = dao.delForder(forderid);
- //文件表记录删除
- flag = dao.delFileByForderId(forderid);
- if(flag ==true){
- //成功
- request.setAttribute("task","delsuc");
- return mapping.findForward("suc");
- }else{
- request.setAttribute("task","delrror");
- return mapping.findForward("error");
- }
- }
- /**
- * 上传文件
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward uploadfile(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- FolderForm folderForm = (FolderForm) form;
- return null;
- }
- public FolderDao getDao() {
- return dao;
- }
- public void setDao(FolderDao dao) {
- this.dao = dao;
- }
- public FileDao getFiledao() {
- return filedao;
- }
- public void setFiledao(FileDao filedao) {
- this.filedao = filedao;
- }
- }