服务器为每一个浏览器实例对应一个session。这个session有自己的一个独立id,这个id保存在浏览器的cookie中(这个cookie貌似随着这个浏览器实例的关闭而清除),访问web服务器的时候,web服务会根据你cookie中的sessionId来决定重新创建一个session还是使用已经存在的session。如果使用桌面的ie图标打开一个IE窗口,这个窗口属于一个新的浏览器实例(其中不包含sessionid信息),这时候用这个IE访问web服务器的时候web服务器会为这个浏览器实例新创建一个httpsession,sessionId也是新的(sessionId保存到本地的cookie中),不会对你以前打开的窗口中的session产生覆盖,关闭ie窗口的时候cookie中的信息也就清除掉了。
补充一点,可以通过人为的输入参数sessionId通知web服务器你使用的是哪个session(如果服务器存在这个session的话)。
*****************************************************************************************************************************************
- <form action="verifyLogin.do" method="post" name="form">
- <table>
- <tr align="center">
- <td colspan="6" align="left"><fieldset STYLE='border:0;padding:14px;filter:glow(color=#0080ff,strength=3);letter-spacing:2px;'><font STYLE='font:12px/14px;color:#ffffff;font-weight:bold;'>请输入帐号和密码:</font></fieldset>
- </td>
- </tr>
- <tr>
- <td align="right">用户名:</td>
- <td><input type="text" name="name" style="{ width: 100px;height: 15px;}" ></td>
- <td align="right">密 码:</td>
- <td><input type="password" name="pwd" style="{ width: 100px;height: 15px;}"></td>
- <td>
- <%-- <select name="authority" size="1">--%>
- <%-- <option value="11">管理员</option>--%>
- <%-- <option value="00">普通用户</option>--%>
- <%-- </select>--%>
- <input type="hidden" name="authority" value="11" >
- </td>
- </tr>
- <tr align="center">
- <td colspan="6" align="center">
- <input name="" type="button" value="提 交" onMouseOver="this.style.backgroundColor='red';" onMouseOut="this.style.backgroundColor='';" class="button" onClick="check()">
- <input name="" type="reset" value="重 置" onMouseOver="this.style.backgroundColor='red';" onMouseOut="this.style.backgroundColor='';" class="button">
- </td>
- </tr>
- </table>
- </form>
- String name=request.getParameter("name");
- String pwd=request.getParameter("pwd");
- String ip = request.getRemoteHost();
- //String Ip=request.getRemoteAddr();
- User user=UserHelp.getUserByName(name);
- String err="";
- if(user!=null){
- if (user.getPwd().equals(pwd)){
- //out.println("验证成功!");
- boolean flag = true;
- List<HttpSession> sessions = (List<HttpSession>)application.getAttribute("sessionlist");
- for(int i = 0;i<sessions.size();i++){
- HttpSession ses = null;
- try{
- ses = sessions.get(i);
- User usr = (User)ses.getAttribute("user");
- String cuip = (String)ses.getAttribute("remoteHost");
- if(null!=usr&&usr.getName().equals(user.getName())&&!ip.equals(cuip)){//login repeatly!
- flag = false;
- err="<center><font color='red'>对不起该用户已经有人登录,您不能重复登录!</font></center><br><br>";
- out.println(err);
- break;
- }
- }catch(Exception e){
- sessions.remove(i);
- }
- }
- if(flag){
- session.setAttribute("user",user);
- session.setAttribute("remoteHost",ip);
- sessions.add(session);
- application.setAttribute("sessionlist",sessions);
- }
- if(flag&&user.getAuthority().equals("11")){
- response.sendRedirect("manageFrames2.htm");
- }
- if(flag&&user.getAuthority().equals("00")){
- response.sendRedirect("manageFrames1.htm");
- }
- }
- else{
- err="<center>密码错误,请重新登录!</center><br><br>";
- out.println(err);
- }
- }
- else{
- err="<center>无此用户,请重新登录!</center><br><br>";
- out.println(err);
- }