• 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>Insert title here</title>
    </head>
    <body>
    <%
    session.invalidate();
    %>
    <form action="yanzheng.jsp" method="post">
    用户名:<input type="text" name="yonghu"> 
    密码:<input type="password" name="mima">
    <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>
    <%
    try{
    String yonghu=new String(request.getParameter("yonghu").getBytes("ISO-8859-1"),"UTF-8");
    String mima=request.getParameter("mima");
    
    
        if(yonghu.equals("小小")&& mima.equals("123"))
        {
            session.setAttribute("yonghu", yonghu);
            response.sendRedirect("zhuye.jsp");
            
        }
        else
        {
            
            out.print("用户名或密码错误,请重新输入");
            response.setHeader("refresh", "3;URL=denglu.jsp");
        }
    
    
    }
    catch(Exception e)
    {
    out.print("请从登录界面登录");
    response.setHeader("refresh", "3;URL=denglu.jsp");
    }
    %>
    
    </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=GB2312-80">
    <title>Insert title here</title>
    </head>
    <body>
    <%
    
    Object obj=session.getAttribute("yonghu");
    if(obj==null)
    {
    out.print("请先登录");
    response.setHeader("refresh","3;URL=denglu.jsp");
    }
    else
    {
        String a=new String(obj.toString());
        out.print("欢迎&nbsp;"+a+"&nbsp;登录"); 
    %>
    <br>
    <a href="denglu.jsp"><input type="button" value="退出登录"></a>
    <%
    } %> 

    </body> </html>

  • 相关阅读:
    何时覆盖hashCode()和equals()方法
    JMeter结果树响应数据中文乱码
    HTTP详解
    HTTP协议 (一) HTTP协议详解
    我的cheatsheet
    js 加alert后才能执行方法
    百度云开发者笔记
    sudo: unable to resolve host ubuntu提示的解决
    NUERAL RELATION EXTRACTION WITH MULTI-LINGUAL ATTENTION》阅读笔记
    今天看论文
  • 原文地址:https://www.cnblogs.com/wenwen123/p/5624719.html
Copyright © 2020-2023  润新知