zoukankan      html  css  js  c++  java
  • jsp 练习 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="NewFile1.jsp">
    用户名:<input type="text" name="name">
    密码:<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 name=request.getParameter("name");
    String pw=request.getParameter("password");
    if(name!=null&&pw!=null)
    {
        String n=new String(name.getBytes("ISO-8859-1"),"UTF-8");
        if(n.equals("张三")&&pw.equals("123"))
        {
            out.print("登录成功");
            session.setAttribute("name", n);
            response.setHeader("refresh", "3;URL=NewFile2.jsp");
            
        }
        else
        {
            out.print("用户名或密码错误,正在跳转登录页面");
            response.setHeader("refresh", "5;URL=NewFile.jsp");
        }
    }
    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>
    <%
    Object obj=session.getAttribute("name");
    
    if(obj!=null)
    {
        out.print("欢迎登录,"+obj.toString());
        
    }
    else
    {
        out.print("请以正确的方式登录");
        response.setHeader("refresh", "3;URL=NewFile.jsp");
    }
    %>
    <br>
    <a href="NewFile.jsp">退出登录</a>
    </body>
    </html>

  • 相关阅读:
    深入理解Node.js垃圾回收与内存管理
    【File System】Node.js中文件操作模块File System
    【事件流】事件冒泡和事件捕获
    undefined 和null的区别?
    localStorage实现登录注册功能
    解刨for循环
    react中嵌入高德地图并Marker标点
    react页面中嵌入地图,标识出某个地点,使用插件react-amap
    react中使用antd的List组件,以及下载文件,List隔行变色
    公众号页面数据处理
  • 原文地址:https://www.cnblogs.com/wallan/p/5625743.html
Copyright © 2011-2022 走看看