⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 roleaction.java

📁 基于J2EE的办公自动化系统。实现流程定义流程办理等。运用了hibernate+struts+spring框架综合运用的系统。
💻 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.office.role;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
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.util.XPage;

/**
 * MyEclipse Struts Creation date: 01-21-2008
 * 
 * XDoclet definition:
 * 
 * @struts.action path="/role" name="roleForm" input="/Jsp_file/role/role.jsp"
 *                parameter="method" scope="request" validate="true"
 */
public class RoleAction extends DispatchAction {

	private InRoleDAO roledao;

	public ActionForward query(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		
		RoleForm roleForm = (RoleForm) form;		
		int currentPage = 1;		
		try {
			currentPage = Integer.parseInt(request.getParameter("currentPage"));
		} catch (Exception e) {
			currentPage = 1;
		}
		int count = 3;		
		Trole info = new Trole();
		try {
			BeanUtils.copyProperties(info, roleForm);
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		XPage rolepage = roledao.getRolelist(currentPage, count, info);
		
		request.setAttribute("rolepage", rolepage);
		return mapping.findForward("rolelist");
	}

	public ActionForward add(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){
		
		RoleForm roleForm = (RoleForm) form;	
		roleForm.setMethod("addlist");
		
		List funlist = null;		
		funlist = roledao.getFfunction();		
		request.setAttribute("funlist",funlist);
		return mapping.getInputForward();
	}
	
	public ActionForward addlist(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {

		String[] rolefun = request.getParameterValues("rolefun");
		RoleForm roleForm = (RoleForm) form;
		Trole info = new Trole();
						
		int num = rolefun.length;
		Trolefunction[] rfun = new Trolefunction[num];		
		for(int i=0;i<num;i++){
			rfun[i] = new  Trolefunction();
			rfun[i].setFid(Integer.parseInt(rolefun[i]));
			rfun[i].setRole(info);
			info.getRolefunction().add(rfun[i]);
		}

		try {
			//info目的地  userForm 源
			BeanUtils.copyProperties(info,roleForm);
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		
		
		boolean flag = roledao.addList(info);		
		if (flag) {
			// 去列表页面,并显示成功信息
			request.setAttribute("msg", "添加角色成功");
			return mapping.findForward("query");
		} else {
			// 去添加页面,并显示失败信息
			request.setAttribute("msg", "添加角色失败");
			return mapping.getInputForward();
		}
	}
	
	public ActionForward update(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		RoleForm roleForm = (RoleForm) form;
		roleForm.setMethod("edit");
		Trole info = roledao.getRfinfo(roleForm.getRid());
		
		try {
			BeanUtils.copyProperties(roleForm,info);
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		List rflist = null;
		List funlist = null;
		funlist = roledao.getFfunction();
		rflist = roledao.getRfList(roleForm.getRid());
		request.setAttribute("rflist",rflist);
		request.setAttribute("funlist",funlist);
		return mapping.getInputForward();
	}
	
	public ActionForward edit(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		
		String[] rolefun = request.getParameterValues("rolefun");
		RoleForm roleForm = (RoleForm) form;
		Trole info = new Trole();
		try {
			BeanUtils.copyProperties(info,roleForm);
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		
		int num = rolefun.length;
		Trolefunction[] rfun = new Trolefunction[num];		
		for(int i=0;i<num;i++){
			rfun[i] = new  Trolefunction();
			rfun[i].setFid(Integer.parseInt(rolefun[i]));
			rfun[i].setRole(info);
			info.getRolefunction().add(rfun[i]);
		}
		
		boolean flag = roledao.editList(info);
		if (flag) {
			// 去列表页面,并显示成功信息
			request.setAttribute("msg", "修改角色成功");
			return mapping.findForward("query");
		} else {
			// 去添加页面,并显示失败信息
			request.setAttribute("msg", "修改角色失败");
			return mapping.getInputForward();
		}
	}
	
	public ActionForward del(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
				
		RoleForm roleForm = (RoleForm) form;
		boolean flag1 = roledao.getUserForRid(roleForm.getRid());
		if(flag1){
			request.setAttribute("msg", "该角色还有用户使用,不能删除!");
			return mapping.findForward("query");
		} else {
			Trole info = roledao.getRfinfo(roleForm.getRid());
			try {
				BeanUtils.copyProperties(roleForm,info);
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			boolean flag = roledao.delList(info);
			if (flag) {
				// 去列表页面,并显示成功信息
				request.setAttribute("msg", "删除角色成功");
				return mapping.findForward("query");
			} else {
				// 去添加页面,并显示失败信息
				request.setAttribute("msg", "删除角色失败");
				return mapping.findForward("query");
			}
		}
	}

	
	public ActionForward checkName(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws IOException {
		
		PrintWriter out = response.getWriter();
		RoleForm roleForm = (RoleForm) form;
		
		if(!(roleForm.getRname()==null)&&!roleForm.getRname().equals("")){
			boolean flag = roledao.getRoleByName(roleForm.getRname());
			if (flag) {
				// 去列表页面,并显示成功信息
				out.print("此角色已存在,请更换!");
			} else {
				out.print("可以使用!");
			}
		} else {
			out.print("角色名称不能为空!");
		}
		return null;
	}
	
	
	
	
	
	
	public InRoleDAO getRoledao() {
		return roledao;
	}

	public void setRoledao(InRoleDAO roledao) {
		this.roledao = roledao;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -