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>
    

     运行结果:

  • 相关阅读:
    葡萄庄园 [图论]
    硬币游戏 [博弈论, 思维题]
    烹饪 [容斥]
    BZOJ1597 [Usaco2008 Mar]土地购买 [斜率优化]
    TCP IP协议
    soap协议
    xml的语法规则
    fiddler的使用
    常见默认端口
    智能休眠时间的使用
  • 原文地址:https://www.cnblogs.com/jakeasd/p/5620649.html
Copyright © 2011-2022 走看看