loginmanageraction.java
来自「电信计费项目 该系统在Sun Solaris下开发,运行于Apache Tom」· Java 代码 · 共 92 行
JAVA
92 行
package com.tarena.netctoss.controller.actions;
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.MappingDispatchAction;
import com.tarena.netctoss.model.biz.entity.*;
import com.tarena.netctoss.model.biz.*;
public class LoginManagerAction extends MappingDispatchAction {
public ActionForward userLogin(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws UserActionException {
ActionForward forward = mapping.findForward("loginfail");
IUserService service = ServiceFactory.getUserService();
String login_name = request.getParameter("login_name");
String login_password = request.getParameter("login_password");
System.out.println(login_name+"="+login_password);
try {
User user = service.findUser(login_name, login_password);
if (user != null) {
HttpSession session = request.getSession(true);
session.setAttribute("login_user", user);
session.setAttribute("type", "user");
forward = mapping.findForward("loginsuccess");
}
} catch (RuntimeException e) {
e.printStackTrace();
throw new UserActionException();
}
return forward;
}
public ActionForward adminLogin(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws UserActionException {
ActionForward forward = mapping.findForward("loginfail");
IAdminService service = ServiceFactory.getAdminService();
String login_name = request.getParameter("login_name");
String login_password = request.getParameter("login_password");
try {
Admin admin = service.findAdmin(login_name, login_password);
if (admin != null) {
HttpSession session = request.getSession(true);
session.setAttribute("login_user", admin);
session.setAttribute("type", "admin");
forward = mapping.findForward("loginsuccess");
}
} catch (RuntimeException e) {
e.printStackTrace();
throw new UserActionException();
}
return forward;
}
public ActionForward logout(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws UserActionException {
ActionForward forward = mapping.findForward("success");
IAdminService aservice = ServiceFactory.getAdminService();
IUserService uservice = ServiceFactory.getUserService();
HttpSession session = request.getSession(false);
try {
Object obj = session.getAttribute("login_user");
if (obj instanceof Admin) {
Admin admin = (Admin) obj;
admin.setClose_date(admin.getEnroll_date());
admin.setEnroll_date(new java.sql.Date(System
.currentTimeMillis()));
aservice.modify(admin);
} else if (obj instanceof User) {
User user = (User) obj;
user.setClose_date(user.getEnroll_date());
user.setEnroll_date(new java.sql.Date(System
.currentTimeMillis()));
uservice.modify(user);
}
session.removeAttribute("login_user");
session.removeAttribute("type");
session.invalidate();
} catch (RuntimeException e) {
e.printStackTrace();
}
return forward;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?