62,620
社区成员
发帖
与我相关
我的任务
分享package smc.web.action;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import javax.ejb.CreateException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import smc.web.form.*;
import smc.session.login.*;
import smc.toolkit.jndi.CJndiNamesFactory;
import smc.toolkit.*;
import smc.toolkit.dto.status.CPrintStatusDTO;
import java.util.*;
public class CLoginAction extends Action {
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
/*
Properties properties = System.getProperties();
Enumeration enmu = properties.keys();
while(enmu.hasMoreElements())
{
String strKey = (String)enmu.nextElement();
String strValue = (String)properties.getProperty(strKey);
System.out.println(strKey + ":" + strValue);
}
*/
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);
String strError = "";
//
// String op = request.getParameter("op");
// System.out.println("op.........." + op);
// if (op != null) {
//
// //request.getSession().invalidate();
//
// return mapping.findForward("loginagin");
// } else {
/*
Enumeration enu = request.getHeaderNames();
while(enu.hasMoreElements())
{
String strHeader = (String)enu.nextElement();
System.out.println(strHeader +":" + request.getHeader(strHeader));
}
*/
System.out.println("Url: " + request.getRequestURL());
int nReturn = 0;
try {
CLoginInfoHome loginInfoHome =
(CLoginInfoHome) CEJBHomeFactory.getFactory().lookUpHome(
CLoginInfoHome.class,
CJndiNamesFactory.JNDI_LOGIN);
CLoginInfo loginInfo = loginInfoHome.create();
CLoginForm loginForm = (CLoginForm) form;
String strUser = loginForm.getStrUser();
String strPassword = loginForm.getStrPassword();
if (loginInfo.isFirstLogin()) {
return mapping.findForward("menuPage");
}
nReturn = loginInfo.isLoginValid(strUser, strPassword);
if (nReturn == 0) {
request.getSession().invalidate();
request.getSession().setAttribute("User", strUser);
//save client os infomation
String strUserAgent =
(String) request.getHeader("User-Agent");
System.out.println(strUserAgent);
getClientOSType(strUserAgent, request);
CPrintStatusDTO statusDTO;
if (request.getSession().getAttribute("printStatusDTO")
== null) {
statusDTO = new CPrintStatusDTO();
statusDTO.clear();
if (loginInfo.isPrintLogin(strUser)) {
statusDTO.setStrLoginType("PRINT");
statusDTO.setStrLoginPrintCom(
loginInfo.getPrintcom());
if (smc
.toolkit
.database
.util
.CUpdateDatabase
.isPrintComHasFtp(loginInfo.getPrintcom()))
//statusDTO.getStrPrintComCode()))//loginInfo.getPrintcom(strUser)))
{
statusDTO.setStrHasFtp("true");
}
} else {
statusDTO.setStrLoginType("SMC");
}
statusDTO.setStrStatus("init");
request.getSession().setAttribute(
"printStatusDTO",
statusDTO);
}
if (loginInfo.isPrintLogin(strUser)) {
return mapping.findForward("printPage");
} else {
return mapping.findForward("menuPage");
}
}
} catch (Exception e) {
e.printStackTrace();
}
switch (nReturn) {
case 1 :
{
strError = "database";
break;
}
case 2 :
{
strError = "user";
break;
}
case 3 :
{
strError = "password";
break;
}
case 4 :
{
strError = "userinvalid";
break;
}
}
// }
request.setAttribute("Error", strError);
return mapping.findForward("inputErrorPage");
}
private void getClientOSType(
String strOSInfo,
HttpServletRequest request) {
HttpSession session = request.getSession();
int iPosition;
//ネ。オテチスクィコナヨョシ莊トトレネン。」
iPosition = strOSInfo.indexOf("(");
if (iPosition > -1) {
strOSInfo = strOSInfo.substring(iPosition + 1, strOSInfo.length());
}
iPosition = strOSInfo.indexOf(")");
if (iPosition > -1) {
strOSInfo = strOSInfo.substring(0, iPosition);
}
if ((strOSInfo.indexOf("Window") > -1)
|| (strOSInfo.indexOf("Win2000") > -1)) {
session.setAttribute("OSType", "Window");
} else if (strOSInfo.indexOf("Linux") > -1) {
session.setAttribute("OSType", "Linux");
} else if (strOSInfo.indexOf("Mac") > -1) {
if (strOSInfo.indexOf("5.0") > 0)
session.setAttribute("OSType", "Mac9");
else if (strOSInfo.indexOf("5.23") > 0)
session.setAttribute("OSType", "Mac10");
}
}
}