LoginAction
来源:互联网 发布:拉圈圈软件免费 编辑:程序博客网 时间:2024/05/13 15:55
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package zthh.manager.czl.action;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.ServletContext;
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 zthh.manager.commons.Md5Code;
import zthh.manager.commons.WebUtil;
import zthh.manager.czl.biz.IEmployeeBiz;
import zthh.manager.entity.Employee;
/**
* MyEclipse Struts Creation date: 03-08-2010
*
* XDoclet definition:
*
* @struts.action parameter="op" validate="true"
* @struts.action-forward name="toEmployee" path="/index.jsp"
*/
public class LoginAction extends DispatchAction {
private IEmployeeBiz employeeBiz;
public void setEmployeeBiz(IEmployeeBiz employeeBiz) {
this.employeeBiz = employeeBiz;
}
/**
* Method execute
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws IOException
*/
@SuppressWarnings("unchecked")
public ActionForward doLogin(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException {
String loginid = request.getParameter("loginID");
String pwd = request.getParameter("pwd");
String saveLogin = request.getParameter("saveLogin");
PrintWriter out = response.getWriter();
if (loginid != null && !"".equals(loginid) && pwd != null
&& !"".equals(pwd)) {
pwd = Md5Code.EncoderByMd5(pwd.trim());
Employee employee = employeeBiz.getEmployeeByLogin(loginid, pwd);
if (employee != null && employee.getId() != null) {
if (employee.getEnabled() == 1) {
HttpSession session = request.getSession();
ServletContext servletContext = session.getServletContext();
Boolean temp = true;
if (servletContext.getAttribute("eList") != null) {
List<Integer> list = (List<Integer>) servletContext
.getAttribute("eList");
if (list.contains(employee.getId())) {
temp = false;
} else {
list.add(employee.getId());
servletContext.setAttribute("eList", list);
}
} else {
List<Integer> list = new ArrayList<Integer>();
list.add(employee.getId());
servletContext.setAttribute("eList", list);
}
if (temp) {
employee.setLoginTime(new Date());
employeeBiz.updateEmployee(employee);
session.setAttribute("Employee", employee);
if (saveLogin != null && !"0".equals(saveLogin)) {
WebUtil.addCookie(response, "zthhloginID", loginid,
Integer.valueOf(saveLogin) * 24 * 60 * 60);
WebUtil.addCookie(response, "zthhpwd", pwd, Integer
.valueOf(saveLogin) * 24 * 60 * 60);
}
out
.print("<script type='text/javascript'>alert('您已成功登录!');location.href='login.do?op=doShowIndex';</script>");
} else {
out
.print("<script type='text/javascript'>alert('该账号已登录!');location.href='index.jsp';</script>");
}
} else {
switch (employee.getEnabled()) {
case 2:
out
.print("<script type='text/javascript'>alert('该账号已不能使用!');location.href='index.jsp';</script>");
break;
default:
out
.print("<script type='text/javascript'>alert('该账号已不能使用!');location.href='index.jsp';</script>");
break;
}
}
} else {
out
.print("<script type='text/javascript'>alert('登陆名或密码错误!');location.href='index.jsp';</script>");
}
} else {
out
.print("<script type='text/javascript'>alert('请正确填写登陆名或密码!');location.href='index.jsp';</script>");
}
return null;
}
/**
* Method execute
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws IOException
* @throws IOException
*/
public ActionForward doShowIndex(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException {
HttpSession session = request.getSession();
Employee employee = (Employee) session.getAttribute("Employee");
if (employee != null && employee.getId() != null) {
switch (employee.getPower()) {
case 1:
return mapping.findForward("toGM");
case 2:
case 3:
case 4:
return mapping.findForward("toSell");
default:
session.removeAttribute("Employee");
break;
}
}
PrintWriter out = response.getWriter();
out
.print("<script type='text/javascript'>alert('请先登录!');location.href='index.jsp';</script>");
return null;
}
/**
* Method execute
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws IOException
* @throws IOException
* @throws IOException
*/
@SuppressWarnings("unchecked")
public ActionForward doLogout(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException {
HttpSession session = request.getSession();
Employee employee = (Employee) session.getAttribute("Employee");
if (employee != null && employee.getId() != null) {
ServletContext servletContext = session.getServletContext();
if (servletContext.getAttribute("eList") != null) {
List<Integer> list = (List<Integer>) servletContext
.getAttribute("eList");
if (list.remove(employee.getId())) {
servletContext.setAttribute("eList", list);
}
}
}
session.removeAttribute("Employee");
WebUtil.addCookie(response, "zthhloginID", "", 0);
WebUtil.addCookie(response, "zthhpwd", "", 0);
PrintWriter out = response.getWriter();
out
.print("<script type='text/javascript'>location.href='index.jsp';</script>");
return null;
}
/**
* Method execute
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws IOException
* @throws IOException
* @throws IOException
* @throws IOException
*/
public ActionForward doShowTip(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException {
HttpSession session = request.getSession();
Employee employee = (Employee) session.getAttribute("Employee");
PrintWriter out = response.getWriter();
if (employee != null && employee.getId() != null) {
out.print(1);
} else {
out.print(0);
}
return null;
}
}
- LoginAction
- Struts框架 loginAction
- loginAction-validation.xml
- spring的LoginAction
- Login/LoginAction.class.php
- Struct2 配置2 LoginAction.java
- public class LoginAction extends ActionSupport {
- loginAction中对Application的应用
- com.test.struts.action/LoginAction.java---1
- com.test.struts.action/LoginAction.java---2
- Action class [loginAction] not found - action - file
- java.lang.NullPointerException&com.cb.action.LoginAction.execute(LoginAction.java:48)
- No result defined for action action.LoginAction and result success
- Struts2中loginAction的no result success问题
- @Controller("loginAction") @Scope("prototype") @Resource(name="loginService")
- Struts2异常!!!(原因LoginAction没有实现相应接口:SessionAware)
- Unable to instantiate Action, loginAction, defined for 'login' in namespace
- No result defined for action action.LoginAction and result success
- TextBox的AutoPostBack="True"引起的误会
- WebUtil
- Ubuntu 8.10控制台启用FrameBuffer模块
- 方法整理【去除数组重复的项】
- raid技术
- LoginAction
- 以此贴作证--开始学习计算机(不在玩游戏!)I think , I can
- 表(table)数据合并为一个字符串的SQL语句
- 【每天算法3】:用java语言实现,二维Vector的排序组合
- Ubuntu系统启动过程详解
- Spring中HttpInvoker实例
- 日本网民嘲讽中国人生存能力似蟑螂
- 利用DbProviderFactory实现数据操作跨数据库数据操作类
- 套接filestream