zoukankan      html  css  js  c++  java
  • 学习记录 java session保存用户登录

     1 <%@ page language="java" contentType="text/html; charset=UTF-8"
     2     pageEncoding="UTF-8"%>
     3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
     4 <html>
     5 <head>
     6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     7 <title>Insert title here</title>
     8 </head>
     9 <body>
    10 <%
    11 
    12 //检查session,取得session信息
    13 Object obj = session.getAttribute("username");
    14 if(obj != null)
    15 {
    16     out.print("欢迎登录 "+obj.toString());    
    17 }
    18 else
    19 {
    20 out.print("会话超时,请重新登录系统");    
    21 //3秒后跳转到用户界面
    22 response.setHeader("refresh", "3;URL=Login.jsp");
    23 }
    24 %>
    25 主页面
    26 <br>
    27 <a href="Login.jsp">退出登录</a>
    28 </body>
    29 </html>
     1 <%@ page language="java" contentType="text/html; charset=UTF-8"
     2     pageEncoding="UTF-8"%>
     3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
     4 <html>
     5 <head>
     6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     7 <title>Insert title here</title>
     8 </head>
     9 <body>
    10 登录页面
    11 <br>
    12 <%
    13 //销毁session
    14 session.invalidate();
    15 %>
    16 
    17 <form action="TestPW.jsp" method = "post">
    18 用户名:<input type="text"name = "username">
    19 密码:<input type="password"name = "password">
    20 <input type="submit" value="登录">
    21 </form>
    22 </body>
    23 </html>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!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">
    <title>Insert title here</title>
    </head>
    <body>
    <%
    //验证用户登录信息是否正确
    
    String un =  request.getParameter("username");
    String pw =  request.getParameter("password");
    
    if(un != null && pw != null)
    {
        //如果正确  就创建session,并跳转到main.jsp
        if(un.equals("asd") && pw.equals("123"))
        {
            //记录用户信息
            session.setAttribute("username", un);
            
            
            //跳转到系统主页面
            response.sendRedirect("Main.jsp");
            
        }
        else
        {
            //否则就提示登录错误
            out.print("用户名或密码错误");
        }
    }
    else
    {
        out.print("请以正常的方式访问系统");
        }
    
    %>
    
    
    
    </body>
    </html>

  • 相关阅读:
    安德鲁斯称三步系统相机
    Swift游戏开发实战教程(霸内部信息大学)
    ORA-00911:无效字符错误
    Java对多线程~~~Fork/Join同步和异步帧
    jquery跨域请求解决方案(我们寻找,我还没有添加验证)
    mysql 的load data infile要使用
    完整详细的说明GCD列(一)dispatch_async;dispatch_sync;dispatch_async_f;dispatch_sync_f
    Linux查看非root流程执行
    Android_显示器本身被卸载应用程序
    关于微软公有云Azure会计标准
  • 原文地址:https://www.cnblogs.com/zhoudi/p/5626101.html
Copyright © 2011-2022 走看看