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>
    <form action="session0627.jsp" method="post">
    <table>
    <tr>
    <td>用户名:</td>
    <td><input type="text" name="username"/></td>
    </tr>
    
    <tr>
    <td>密码:</td>
    <td><input type="password" name="password"/></td>
    </tr>
    <tr>
    <td><input type="submit" value="登录"/></td>
    
    </tr>
    
    </table>
    
    
    
    </form>
    
    
    
    
    </body>
    </html>
    设置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>
    <%
    String username=new String(request.getParameter("username").getBytes("ISO-8859-1"),"UTF-8");
    session.setAttribute("name", username);
    String password=request.getParameter("password");
    session.setAttribute("mima", password);
    %>
    登录成功
    
    
    
    </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>
    您的用户信息为:<br>
    <%
    String str=session.getAttribute("name").toString();
    String str1=session.getAttribute("mima").toString();
    
    out.print("用户名:"+str+"<br>");
    out.print("密码:"+str1);
    %>
    
    
    </body>
    </html>

    运行结果:

  • 相关阅读:
    【基础算法-模拟-例题-*校长的问题】-C++
    【基础算法模拟+例题】-C++
    Chrome开发者调试工具 //TODO
    Javascript面试题&知识点汇总(持续汇总...)
    HTML面试题&知识点汇总(持续汇总...)
    零基础学习Web前端开发
    UML
    江西财经大学第一届程序设计竞赛 F
    江西财经大学第一届程序设计竞赛 E
    江西财经大学第一届程序设计竞赛 D
  • 原文地址:https://www.cnblogs.com/miss123/p/5620642.html
Copyright © 2011-2022 走看看