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

📄 loginaction.java

📁 机房运营维护系统 java+oracle9i 使用struts 分用户权限 完成用户对机房信息的增删改查等功能
💻 JAVA
字号:
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.yourcompany.struts.action;

import java.util.List;
import java.util.Map;

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

import ms.hibernate.Emp;
import ms.hibernate.Module;
import ms.hibernate.Popedom;
import ms.hibernate.Role;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import com.model.IEmpDao;
import com.yourcompany.struts.form.LoginForm;

/**
 * MyEclipse Struts Creation date: 09-18-2007
 * 
 * XDoclet definition:
 * 
 * @struts.action path="/login" name="loginForm" input="/index.jsp"
 *                scope="request" validate="true"
 * @struts.action-forward name="faild" path="/index.jsp"
 * @struts.action-forward name="success" path="/main/main.jsp"
 */
public class LoginAction extends Action {
	private IEmpDao empDao;

	public IEmpDao getEmpDao() {
		return empDao;
	}

	public void setEmpDao(IEmpDao empDao) {
		this.empDao = empDao;
	}

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		LoginForm loginForm = (LoginForm) form;
		HttpSession session = request.getSession(true);
		session.invalidate();
		session = request.getSession(true);
			String target = "success";
			Map<String, Object> map = this.getEmpDao().findById(
					loginForm.getEmpid());

			ActionErrors errors = new ActionErrors();
			if (map == null) {
				errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
						"lable.login.notid"));
				target = "faild";
			} else {
				Emp emp = (Emp) map.get("emp");
				if (!emp.getPassword().equals(loginForm.getPassword())) {
					errors.add(ActionMessages.GLOBAL_MESSAGE,
							new ActionMessage("lable.login.notpassword"));
					target = "faild";
				} else {
					List<Module> modules = (List<Module>) map.get("roles");
					if (modules == null || modules.size() == 0) {
						errors.add(ActionMessages.GLOBAL_MESSAGE,
								new ActionMessage("lable.notrloe"));
						target = "faild";
					} else {
						session.setAttribute("roomPope", this.getEmpDao().findRMangerPopedomById(emp.getEmpid()));
						session.setAttribute("deptPope", this.getEmpDao().findDMangerPopedomById(emp.getEmpid()));
						session.setAttribute("empPope", this.getEmpDao().findEMangerPopedomById(emp.getEmpid()));
						session.setAttribute("rolePope", this.getEmpDao().findPMangerPopedomById(emp.getEmpid()));
						session.setAttribute("logPope", this.getEmpDao().findLMangerPopedomById(emp.getEmpid()));
						session.setAttribute("empid", emp.getEmpid());
						session.setAttribute("empname", emp.getEname());
						request.setAttribute("modules", modules);
					}
				}
			}
			if (!errors.isEmpty()) {
				this.saveErrors(request, errors);
			}

			return mapping.findForward(target);
		
	}
}

⌨️ 快捷键说明

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