国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

session對象的簡單實例

2019-11-14 14:51:21
字體:
來源:轉載
供稿:網友

一個session對象的簡單實例:

1、登錄界面:使用簡單的html表單提交界面。

<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
<!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=GB18030">
<title>Insert title here</title>
</head>
<body>
    <form action="do_long.jsp" method="post">
    用戶名:<input type="text" name="usename"/><br><br>
    密碼:<input type="passWord" name="password"/><br><br>
       <input type="submit" value="提交"/>
       <input type="reset" value="重置"/>
    </form>
</body>
</html>

2、request對象獲取用戶名和密碼,判斷是否為空,使用session的setattribute儲存用戶名信息。跳轉到歡迎界面。

<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
<% 
 String usename=request.getParameter("usename");
 String password=request.getParameter("password");
 if(usename!=null&&password!=null){
  session.setAttribute("usename", usename);
  response.setHeader("refresh", "2;URL=welcome.jsp");
 }
 else{
 %>

 用戶名,密碼不能為空。<a href="long.jsp">登錄</a>
 <%}%>

3、歡迎界面

<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
<!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=GB18030">
<title>Insert title here</title>
</head>
<body>
 <%if(session.getAttribute("usename")!=null){%>
 歡迎:<%=session.getAttribute("usename")%>  
 <a href="longout.jsp">注銷</a><br>
 <%}else {%>
 請先登錄
 <a href="long.jsp">登錄</a><br>
 <%} %>
 <%if(session.isNew()){ %>
 歡迎新用戶
 <%}else{ %>
 歡迎老用戶
 <%} %>
</body>
</html>

4、退出界面

<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
<%
 session.invalidate();
 response.setHeader("refresh", "2;URL=welcome.jsp");
%>

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 赣州市| 汝州市| 尖扎县| 长白| 曲靖市| 永福县| 磴口县| 黎城县| 平顶山市| 五寨县| 大化| 清流县| 平舆县| 都兰县| 精河县| 铜川市| 苗栗市| 宁强县| 义马市| 尚志市| 汕头市| 丹阳市| 图木舒克市| 安吉县| 刚察县| 上林县| 青州市| 红原县| 安康市| 鄢陵县| 合作市| 靖远县| 海林市| 吉木萨尔县| 东宁县| 任丘市| 清河县| 黑水县| 彭阳县| 昌吉市| 库车县|