zoukankan      html  css  js  c++  java
  • jsp 运用 session 登录输出

    1、登录页面

    <%@ 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>
    <form action="lianxi1.jsp" method="post">
    用户名:<input type="text" name="name"><br>
    密&nbsp&nbsp&nbsp&nbsp码:<input type="password" name="password"><br>
    <input type="submit" value="登录">
    </form>
    </body>
    </html>
    

     运行并添加数据

    2、把数据添加到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>
    <%
    String name=new String(request.getParameter("name").getBytes("ISO-8859-1"),"UTF-8");
    String password=request.getParameter("password");
    session.setAttribute("name", name);
    session.setAttribute("pword", password);
    %>
    添加session成功
    </body>
    </html>
    

     

    3、输出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>
    <%
    String str=session.getAttribute("name").toString();
    out.print("name="+str);
    String s=session.getAttribute("pword").toString();
    out.print("<br>password="+s);
    %>
    </body>
    </html>
    

     运行结果:

  • 相关阅读:
    CF982E Billiard
    CF385E Bear in the Field
    CF1322C Instant Noodles
    CF359C Prime Number
    CF1117E Decypher the String
    模板整合计划 写了一点qwq慢慢补
    BZOJ 4320
    acwing91:最短哈密顿路径
    P3469 [POI2008]BLO-Blockade
    简易平衡树
  • 原文地址:https://www.cnblogs.com/jakeasd/p/5620649.html
Copyright © 2011-2022 走看看