码迷,mamicode.com
首页 > 其他好文 > 详细

session应用:

时间:2017-04-06 22:31:20      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:div   odi   imp   dtd   logs   for   request   username   get   

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" session="true"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>登录</title>
  </head>
  
  <body>
        sessionID<%=session.getId() %>
        
        <%
            Object username=session.getAttribute("username");
            if(username==null){
                username="";
            }
         %>
        <form action="hello.jsp" method="post">
            username:<input type="text" name="username" 
            value="<%= username %>"/>
            
                <input type="submit" value="Submit"/>
        </form>
  </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" session="true"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>HELLO SESSION</title>
  </head>
  
  <body>
        sessionID<%=session.getId() %>
        <%=request.getParameter("username") %>
        <%
            session.setAttribute("username", request.getParameter("username"));
         %>
    <a href="<%= response.encodeURL("login.jsp") %>">重新登录</a>    
    &nbsp;&nbsp;&nbsp;&nbsp;
    <a href="<%= response.encodeURL("zhuxiao.jsp") %>">注销</a>
  </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" session="true"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>注销</title>
  </head>
  
  <body>
  sessionId:<%=session.getId() %>
        <h3>Session</h3>
        Bye: <%= session.getAttribute("username") %>
    <%
        session.invalidate();
        
     %>
  </body>
</html>

 

session应用:

标签:div   odi   imp   dtd   logs   for   request   username   get   

原文地址:http://www.cnblogs.com/bulrush/p/6675410.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!