用监听器防止重复登录,强迫前一个登录的下线
登录首页(index.jsp)
提交个表单给登录处理页面login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String flag = request.getParameter("flag"); //flag的作用是用来判断是否重复登录
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="form.css" rel="stylesheet" type="text/css" />
<title>登录首页</title>
<script type="text/javascript">
var flag = '<%=flag %>';
if("1"==flag){
alert("你尚未登陆,或者账号在异地登陆,请重新登陆!"); //因别人登录而被迫下线后,弹窗提示要重新登录
}
</script>
</head>
<body>
//提交个表单给登录处理页面login.jsp
<form action="login.jsp" method="post" class="smart-green">
<h1>系统登录</h1>
<label>
<span>用户名:</span>
<input id="username" type="text" name="username"/>
</label>
<label>
<span>密码:</span>
<input id="password" type="password" name="password"/>
</label>
<span> </span>
<label>
<input type="submit" class="button" value="登录"/>
</label>
</form>
</body>
</html>
登录处理页面(login.jsp)
获取表单传来的参数,将登录用户名存储至session对象,接着跳转到主页面main.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String username = request.getParameter("username"); //获取表单传来的参数
String password = request.getParameter("password");
session.setAttribute("loginUser", username);//登