3.权限控制:登陆页面(注意javascript第一句话)

<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
<%@ page import="com.bjpowernode.drp.sysmgr.domain.*" %>    
<%@ page import="com.bjpowernode.drp.sysmgr.manager.*" %>    
<%
	String command = request.getParameter("command");
	
	if ("login".equals(command)) {
		// 用户填写的用户名
		String userId = request.getParameter("userId");
		// 用户填写的密码
		String password = request.getParameter("password");
		// 用户填写的验证码
		String authCodeWriteByUser = request.getParameter("authCode");
		// 正确的验证码
		String authCode = (String)session.getAttribute("rand");
		
		// 如果验证码填写正确,才进行用户名和密码的验证,否则,直接提示验证码填写错误 
		if(!authCodeWriteByUser.equalsIgnoreCase(authCode)) {
			out.println("验证码错误!");
			
		} else {
			// 用户名和密码的验证
			try {
				User user = UserManager.getInstance().login(userId, password);
				 
				//将用户信息设置到session中
				session.setAttribute("user_info", user);
				
				//设置session超时
				//session.setMaxInactiveInterval(60*60);
				
				//重定向到主控页面
				response.sendRedirect(request.getContextPath() + "/main.jsp");
				
			}catch(UserNotFoundException e) {
				out.println(e.getMessage());
				
			}catch(PasswordNotCorrentException e) {
				out.println(e.getMessage());
			}
		}
		
		
	/*
		//演示SQL注入----begin
		boolean success = UserManager.getInstance().login(userId, password);
		if (success) {
			response.sendRedirect(request.getContextPath() + "/main.jsp");
		}
		//演示SQL注入----end
	*/	
	}
%>
<HTML>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
		<TITLE></TITLE>
		<script src="script/client_validate.js"></script>
		
		<SCRIPT language=JavaScript>
			
			// 如果当前帧(登陆页面所在的帧)不在最高层,就让当前帧处于最高帧
			if (window.self != window.top) {
				window.top.location = window.self.location;
			}

			function init(){
				loginForm.userId.focus();
			}
			
			function submitForm()
			{
				if (trim(loginForm.userId.value).length == 0) {
					alert("用户代码不能为空!");
					loginForm.userId.focus();
					return;
				}
				if (trim(loginForm.password.value).length == 0) {
					alert("密码不能为空!");   
					loginForm.password.focus();
					return;	
				}
				loginForm.action = "login.jsp";
				loginForm.method = "post";
				loginForm.submit();
			}
			
			/**
			 * 单击“看不清楚?换一张”,src重新访问servlet(返回另一张图片)
			 */
			function changeAnother() {
				
				// 验证码图片
				var authImage = window.document.getElementById("authImage");
				// src重新访问servlet(返回另一张图片),command=Date(),Date()返回一个精确到秒的时间,每次访问都不一样,访问浏览器找缓存 
				authImage.src = "${pageContext.request.contextPath}/servlet/AuthImageServlet?comand=" + Date();
			}
	</SCRIPT>

	</HEAD>
	<BODY leftMargin=0 topMargin=0 οnlοad=init()>
		<FORM name="loginForm" action="main.html" method=post>
			<input type="hidden" name="command" value="login">
			<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
				<TBODY>
					<TR height=50>
						<TD width=1 background="images/logobar_left.gif">
							<IMG height=50 src="images/spacer.gif" width=1 border=0>
						</TD>
						<TD width="416" align=left vAlign=center
							background="images/logobar_mid.gif">
							<em><strong><font color="#FFFFFF" size="+3"
									face="宋体"><IMG height=1 src="images/spacer.gif" width=5
											border=0>DRP分销管理系统</font> </strong> </em>
						</TD>
						<TD width="478" align=right vAlign=center
							background="images/logobar_mid.gif">
							<div align="right">
								<a href="#"><IMG height=25
										src="images/banner_help_button.gif" width=60 border=0
										name=banner_help_button> </a>
								<IMG height=1 src="images/spacer.gif" width=5 border=0>
							</div>
						</TD>
					</TR>
				</TBODY>
			</TABLE>
			<TABLE height="80%" cellSpacing=0 cellPadding=0 width="100%" border=0>
				<TBODY>
					<TR>
						<!-- The login dialog -->
						<TD vAlign=center align=middle width="100%">
							<!-- login dialog -->
							<TABLE cellSpacing=0 cellPadding=0 border=0>
								<!-- title bar -->
								<TBODY>
									<TR>
										<!-- this row is kind of a dummy row to set the column widths for the whole page-->
										<TD width=8>
											<IMG height=1 src="images/spacer.gif" width=8 border=0>
										</TD>
										<!-- left edge -->
										<TD width=15>
											<IMG height=1 src="images/spacer.gif" width=15 border=0>
										</TD>
										<!-- title image/left margin -->
										<TD width=200>
											<IMG height=1 src="images/spacer.gif" width=200 border=0>
										</TD>
										<!-- main area -->
										<TD width=14>
											<IMG height=1 src="images/spacer.gif" width=14 border=0>
										</TD>
										<!-- right margin -->
										<TD width=11>
											<IMG height=1 src="images/spacer.gif" width=11 border=0>
										</TD>
										<!-- right edge -->
									</TR>
									<TR>
										<TD width=8>
											<IMG height=9 src="images/top_left.gif" width=8 border=0>
										</TD>
										<TD background="images/top.gif" colSpan=3>
											<IMG height=9 src="images/spacer.gif" width=1 border=0>
										</TD>
										<TD width=11>
											<IMG height=9 src="images/top_right.gif" width=11 border=0>
										</TD>
									</TR>
									<TR>
										<TD width=8 background="images/left.gif">
											<IMG height=15 src="images/spacer.gif" width=8 border=0>
										</TD>
										<TD align=left width=140 bgColor=#000033 colSpan=3>
											<FONT face="verdana, arial, helvetica, sans-serif"
												color=#ffffff size=-1> <B>登录DRP</B> </FONT>
										</TD>
										<TD width=11 background="images/right.gif">
											<IMG height=15 src="images/spacer.gif" width=11 border=0>
										</TD>
									</TR>
									<TR>
										<TD width=8>
											<IMG height=9 src="images/middle_left.gif" width=8 border=0>
										</TD>
										<TD background="images/top.gif" colSpan=3>
											<IMG height=9 src="images/spacer.gif" width=1 border=0>
										</TD>
										<TD width=11>
											<IMG height=9 src="images/middleRight.gif" width=11 border=0>
										</TD>
									</TR>
									<TR bgColor=white>
										<TD width=8 background="images/left.gif">
											<IMG height=1 src="images/spacer.gif" width=8 border=0>
										</TD>
										<TD></TD>
										<TD>
											<TABLE cellSpacing=5 cellPadding=0 align=center
												background="images/login1x1.gif" border=0 valign="middle">
												<TBODY>
													<TR>
														<TD>
															<BR>
														</TD>
													</TR>
													<TR>
														<TD align=left>
															<FONT face="verdana, arial, helvetica, sans-serif"
																size=-1>用户名: </FONT>
														</TD>
														<TD align=left>
															<INPUT name="userId" type="text" size="20" maxlength="20">
														</TD>
													</TR>
													<TR>
														<TD align=left>
															<FONT face="verdana, arial, helvetica, sans-serif"
																size=-1>密   码:</FONT>
														</TD>
														<TD align=left>
															<INPUT name="password" type="password" size="21"
																maxlength="20">
														</TD>
													</TR>
													
													<TR>
													
														<TD align=left>
															<FONT face="verdana, arial, helvetica, sans-serif"
																size=-1>验证码:</FONT>
														</TD>
														
														<TD align=left>
															<INPUT name="authCode" id="authCode" type="text" size="6" maxlength="6">
															 
															
															<img id="authImage" name="authIamge" src="${pageContext.request.contextPath}/servlet/AuthImageServlet">
															
															<%-- 单击“看不清楚?换一张”,src重新访问servlet(返回另一张图片) --%>
															<span οnclick="changeAnother()" style="cursor:hand"><font style="font-size: 10px; color: blue">看不清楚?换一张</font></span>
														</TD>
														
													</TR>
													<TR>
														<TD>
															<BR>
														</TD>
													</TR>
												</TBODY>
											</TABLE>
										</TD>
										<TD></TD>
										<TD width=8 background="images/right.gif">
											<IMG height=1 src="images/spacer.gif" width=8 border=0>
										</TD>
									</TR>
									<!-- end of inner main area, right side -->
									<!-- inner button bar -->
									<TR>
										<TD width=8>
											<IMG height=6 src="images/command_top_left.gif" width=8
												border=0>
										</TD>
										<TD background="images/command_top.gif" colSpan=3>
											<IMG height=6 src="images/spacer.gif" border=0>
										</TD>
										<TD width=11>
											<IMG height=6 src="images/command_top_right.gif" width=11
												border=0>
										</TD>
									</TR>
									<TR bgColor=#cccccc>
										<TD width=8>
											<IMG height=20 src="images/command_mid_left.gif" width=8
												border=0>
										</TD>
										<TD>
											<BR>
										</TD>
										<!-- command buttons -->
										<TD align=right colSpan=2>
											<TABLE cellSpacing=0 cellPadding=0 border=0>
												<TBODY>
													<TR>
														<TD>
															<A href="javascript:submitForm()" onc><IMG height=20
																	src="images/login_button.gif" width=71 border=0
																	name=button> </A>
														</TD>
													</TR>
												</TBODY>
											</TABLE>
										</TD>
										<TD width=11>
											<IMG height=20 src="images/command_mid_right.gif" width=11
												border=0>
										</TD>
									</TR>
									<TR>
										<TD width=8>
											<IMG height=8 src="images/command_bottom_left.gif" width=8
												border=0>
										</TD>
										<TD background="images/command_bottom.gif" colSpan=3>
											<IMG height=8 src="images/spacer.gif" width=1 border=0>
										</TD>
										<TD width=11>
											<IMG height=8 src="images/command_bottom_right.gif" width=11
												border=0>
										</TD>
									</TR>
								</TBODY>
							</TABLE>
						</TD>
					</TR>
				</TBODY>
			</TABLE>
			<CENTER></CENTER>
		</FORM>
		<SCRIPT language=JavaScript>

</SCRIPT>
	</BODY>
</HTML>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值