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

    <%@ 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>登录</title>
    </head>
    <body>
    登录页面<br>
    <%
    //销毁session
    session.invalidate();%>
    <form action="testPW.jsp" method="post">
    用户名:<input type="text" name="username"/>
    密码:<input type="password" name="password"/>
    <input type="submit" value="登录"/></form>
    </body>
    </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!=""&&pw!="")
    {
        //如果正确,就创建session,并跳转到main.jsp
        if(un.equals("tom")&&pw.equals("123"))
        {
            session.setAttribute("username", un);
            //跳转到系统主页面
            response.sendRedirect("Main.jsp");
        }
        else
        {
            //否则提示登陆错误
            out.print("用户名或密码错误");
        }
    }
    else
    {
        out.print("请以正确的方式登录");
    }
    
    
    
    //%>
    </body>
    </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>
    
    <% //检查session,取得session信息 
        Object obj=session.getAttribute("username");
        if(obj!=null)
        {
            out.print("欢迎登陆");
        }
        else
        {
            out.print("会话超时,请重新登录系统");
            response.setHeader("refResh", "3;URL=Login.jsp");
        }%>
        主页面
        <br>
        <a href="Login.jsp">退出登录</a>
    </body>
    </html>

  • 相关阅读:
    mybatis
    Enumeration接口
    oracle undo 解析(转载收藏)
    Windows下RabbitMQ的安装
    Aliyun服务器安装Docker
    Redis主从复制、哨兵模式
    Redis持久化-AOF
    Redis持久化-RDB
    Nginx快速上手
    有关Eureka的其他重点配置
  • 原文地址:https://www.cnblogs.com/jskbk/p/5625627.html
Copyright © 2011-2022 走看看