大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE稳定放心使用
jsp之session学习:session.setAttribute(String name,Object value)&session.getAttribute(String name);
part_1 : index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
</head>
<body>
Welcome page
<form action="servlet/BServlet_1206_SetRequestEncoding" method="post">
username :
<input type="text" name="username" value="click2Input" />
<br>
password :
<input type="password" name="password" />
<br />
<input type="submit" value="SubmitTest" />
</form>
<br>
<hr />
<a href="servlet/BServlet_1206_SetRequestEncoding">Get test</a>
<br />
<a href="/ServletDemoProject/jsps/table-for-loop.jsp">点击显示循环表格</a>
<br />
<a href="/ServletDemoProject/generate-sum/form-two-operators.jsp">点击输入两个数字并求和</a>
<br />
<a href="/ServletDemoProject/COOKIE-DEMO/set-cookie.jsp">点击演示Cookie</a>
<br/>
<a href = "/ServletDemoProject/SESSION-DEMO/A-session-set-attribute.jsp">点击设置session</a>
</body>
</html>
part_2 : A-session-set-attribute.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'A-session-set-get-attribute.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<%--Declaration --%>
<%--Script --%>
<%
java.text.SimpleDateFormat sdf_date = new java.text.SimpleDateFormat(
"yyyy-MM-dd");
java.text.SimpleDateFormat sdf_moment = new java.text.SimpleDateFormat(
"HH:mm:ss a");
String date_of_today = sdf_date.format(new java.util.Date());
String moment_of_now = sdf_moment.format(new java.util.Date());
session.setAttribute("date_of_today", date_of_today);
session.setAttribute("moment_of_now", moment_of_now);
%>
<body>
<h3>
Set Attribute :
</h3>
<br />
<h3>
date_of_today :
<%=date_of_today%>
<br />
moment_of_now :
<%=moment_of_now%>
</h3>
<br />
<a href="/ServletDemoProject/SESSION-DEMO/B-session-get-attribute.jsp">点击查看设置Session
Attribute是否成功</a>
<br />
</body>
</html>
part_3 : B-session-get-attribute.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'B-session-set-get-attribute.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<%
String date_of_today = (String) session
.getAttribute("date_of_today");
String moment_of_now = (String) session
.getAttribute("moment_of_now");
%>
<body>
<h3>
Get Attribute :
</h3>
<br />
<h3>
date_of_today :
<%=date_of_today%>
<br />
moment_of_now :
<%=moment_of_now%>
<br />
</h3>
<br />
</body>
</html>
Time : 2016-12-08-%-23:50
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/181107.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...