用户登录完整代码

java action:
LoginForm form=(LoginForm)actionForm;
ActionMessages errors = new ActionMessages();
System.out.println("form.getAction()="+form.getAction());

if ("login".equals(form.getAction())) {
			System.out.println("----------------login--------------");
			AuthCodeCookie authCodeCookie = new AuthCodeCookie(request,response);
			if (!authCodeCookie.getAuthCode().equals(form.getAuthCode())) {//验证码不正确
				errors.add("error.login.authcode", new ActionMessage("error.login.authcode"));
				this.saveErrors(request, errors);
				return mapping.getInputForward();
			}
			
			User user = this.getUserService().get(form.getUserId());
			if(user==null){
				errors.add("error.login.user", new ActionMessage("error.login.user"));
				this.saveErrors(request, errors);
				return mapping.getInputForward();
			}
			
			Util util = new Util();
			if(!util.hash(form.getPassword()).equals(user.getPassword())){
				errors.add("error.login.password", new ActionMessage("error.login.password"));
				this.saveErrors(request, errors);
				return mapping.getInputForward();
			}
			
//			一旦登录成功,创建session
			HttpSession session = request.getSession();
			UserSession userSession = new UserSession();
			userSession.setUser(user);
			session.setAttribute(Constant.USER_SESSION_KEY, userSession);//把UserSession传递到下个页面
			
//			并且修改用户登录时间,登录次数+1
			user.setLastLoginDate(Util.getCurrentDate("yyyyMMdd hhmmss"));
			user.setLoginTimes(Integer.valueOf(user.getLoginTimes().intValue()+1));
			this.getUserService().update(user);
			
			System.out.println("----------------------------------------------------");
//			// 获取用户对应的系统应用菜单
			List allModuleList = this.getModuleService().getModuleTree(
					Integer.parseInt(user.getMenuLevel()));//0代表根菜单
//			List allModuleList = this.getModuleService().getModuleTree(1);//0代表主菜单
					
//			System.out.println("allModuleList.size="+allModuleList.size());
//			for(int i=0;i<allModuleList.size();i++){
//				System.out.println(""+((Module)allModuleList.get(i)).getModuleName());
//			}
			Iterator menu = allModuleList.iterator();
			Vector parentV = new Vector();
			Vector childV = new Vector();
			Module m;
			while (menu.hasNext()) {
				m = (Module) menu.next();
				if(user.getPermission().indexOf("["+m.getId()+"]")!=-1){
					if (m.getParentId().intValue() == 0) {
							parentV.add(m);
					} else {
							childV.add(m);
					}
				}
			}
			request.getSession().setAttribute("parentVector", parentV);
			request.getSession().setAttribute("childVector", childV);
			
			System.out.println("初始化完毕");
			return mapping.findForward("userPanel");
		}


jsp:
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<jsp:useBean id="user_session" scope="session"
	type="com.worthtech.billportal.web.session.UserSession" />
<%
	com.worthtech.billportal.bean.User user = null;
	if (user_session != null)
		user = user_session.getUser();
		
	//根据权限获得菜单,这里权限用Telephone替代一下先
	String str = user.getTelephone();
%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>LEFT</title>
		<link rel="stylesheet" href="css/style.css" type="text/css">
		<script language="JavaScript">
<!--
function doExit(){
	if (confirm("您确定要退出帐单门户系统吗?")){
				window.open("login.portal?action=logout","_parent","");
	}
}
		
//-->
</script>
<script language="JavaScript">
        var w=200;
        function closenavi() {
        w-=200;
        if (w>-10) {window.parent.testframeset.cols = ''+w+',*';repeat=setTimeout("closenavi()",10);}
        else {clearTimeout(repeat);w=200;}
        }

        function loginOutPage() {			
        document.forms[1].SIGN_OFF.click();
        }

        function initIt(){
        divCount = document.all.tags("DIV");
        for (i=0; i<divCount.length; i++) {
        obj = divCount(i);
        if (obj.className == "child" || obj.className == "child1") obj.style.display = "none";
        }
        }

        function expandIt(el) {
	        obj = eval("page" + el);
	        obj2 = eval("main" + el);
	        if (obj.style.display == "none") {
		        obj.style.display = "block";
	        }
	        else {
		        obj.style.display = "none";
	        }
        }

        onload = initIt;

        var judge=0;
        function expandall(o) {
        if (judge==0) {divCount2 = document.all.tags("DIV");
        for (i=0; i<divCount2.length; i++) {
        obj2 = divCount2(i);
        if (obj2.className == "child" || obj.className == "child1" || obj2.style.display == "none") 
        {obj2.style.display = "block";}
        if (obj2.className == "menu")
        {
        //obj2.all.tags('img')[0].src='images/treeimg/tminus.gif';
        obj2.all.tags('img')[0].src='images/openfolder1.gif';
        }
        }

        judge=1;
        o.src='images/icon-closeall.gif';
        o.alt='全部折叠';
        }
        else {divCount2 = document.all.tags("DIV");
        for (i=0; i<divCount2.length; i++) {
        obj2 = divCount2(i);
        if (obj2.className == "child" || obj.className == "child1" || obj2.style.display == "block") 
        {obj2.style.display = "none";}
        if (obj2.className == "menu")
        {
        obj2.all.tags('img')[0].src='images/folder1.gif';
        }
        }

        judge=0;
        o.src='images/icon-expandall.gif';
        o.alt='全部展开';
        }
        }

        function quit(form) {
        window.close()
        }

        function loginOutPage() {			
        document.forms[0].SIGN_OFF.click();
        }

    </script>
	</head>

	<body bgcolor="#D8DADA" class="bodyTop">
		<center>
			<table width="161" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td>
						<table style="margin-top: 10px; margin-bottom: 10px" width="138"
							border="0" align="center" cellpadding="0" cellspacing="0">
							<tr>
								<td>
									<img src="images/001.jpg" width="138" height="6">
								</td>
							</tr>
							<tr>
								<td class="msBack">
									<table width="130" border="0" align="center" cellpadding="3"
										cellspacing="0">
										<tr>
											<td width="19">
												<img src="images/em44.gif" width="19" height="19">
											</td>
											<td class="message">
												您有新的帐单信息
											</td>
										</tr>
										<tr>
											<td>
												<img src="images/em44.gif" width="19" height="19">
											</td>
											<td class="message">
												您有新的支付信息
											</td>
										</tr>
									</table>
								</td>
							</tr>
							<tr>
								<td>
									<img src="images/002.jpg" width="138" height="6">
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
			<logic:iterate id="module" name="parentVector"
				type="com.worthtech.billportal.bean.Module" indexId="index">
				<%
				int i = ((java.lang.Integer) pageContext
				.findAttribute("index")).intValue();
				%>
				<div id=<%="main" + i%> class="title"
					onClick="expandIt(<%="" + i%>); return false">
					<%if(str.indexOf("["+module.getId()+"]")!=-1){%>
					<table class="TableLeftTop" style="margin-top: 10px" width="138"
						border="0" cellspacing="0" cellpadding="4">
						<tr>
							<td background="images/LeftMenuBack.jpg">
								<div align="center">
									<%=module.getModuleName()%>
								</div>
							</td>
						</tr>
					</table>
						<%}%>
				</div>

				<div id=<%="page" + i%> class="child">
					<table class="TableLeftView" width="170" border="0" cellspacing="0"
						cellpadding="0">
						<logic:iterate id="childModule" name="childVector"
							type="com.worthtech.billportal.bean.Module">
							<%
							if(str.indexOf("["+childModule.getId()+"]")!=-1&&childModule.getParentID().intValue()==module.getId().intValue()){
							 %>
							<tr>
								<td width="44">
									<div align="right">
										<img src="images/t.gif" width="19" height="20">
									</div>
								</td>
								<td width="161">
									<a href=<%=childModule.getActionURL()%> target="mainFrame"><%=childModule.getModuleName()%></a>
								</td>
							</tr>
							<%
							}
							%>
						</logic:iterate>
					</table>
				</div>
			</logic:iterate>


			<table style="margin-top: 10px" width="161" border="0"
				cellspacing="0" cellpadding="2">
				<tr>
					<td>
						<table width="141" border="0" align="center" cellpadding="2"
							cellspacing="0">
							<tr>
								<td>
									<div align="center">
										<a href="#" onclick="doExit();"><img
												src="images/ico01.gif" width="65" height="15" border="0"
												class="MouseOver"> </a>
									</div>
								</td>
								<td>
									<div align="center">
										<a
											href="user.portal?action=password"
											target="mainFrame"><img class="MouseOver"
												src="images/ico02.gif" width="65" height="15" border="0">
										</a>
									</div>
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
		</center>
	</body>
</html>

你可能感兴趣的:(html,Web,bean,struts)