jsp之session学习:session.setAttribute(String name,Object value)&session.getAttribute(String name);

jsp之session学习:session.setAttribute(String name,Object value)&session.getAttribute(String name);CSDN博客怎么玩的,菜鸟入门;20161208;

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/181107.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 2D动画编辑器–FSprite Designer

    2D动画编辑器–FSprite Designer

    2021年8月23日
  • 无法解析的外部符号的几种可能

    无法解析的外部符号的几种可能参考:https://blog.csdn.net/educast/article/details/12491473,补充了一项1. lib文件未引入。可使用“#pragmacomment(lib,“winsock.lib”)”语句添加lib引用,也可在项目依赖里添加。2. 类方法的实现未加类标识。如,“CTest::Connect(void){…}”写成了“Conn…

    2022年6月28日
  • python爬虫入门教程(二):开始一个简单的爬虫

    python爬虫入门教程(二):开始一个简单的爬虫python爬虫入门教程,介绍编写一个简单爬虫的过程。

    2022年6月7日
  • SpringMVC-@RequestMapping的参数和用法

    SpringMVC-@RequestMapping的参数和用法RequestMapping里面的注解包含的参数如图:RequestMapping是一个用来处理请求地址映射的注解,可用于类或方法上。用于类上,表示类中的所有响应请求的方法都是以该地址作为父路径。@RequestMapping除了修饰方法,还可来修饰类:类定义处:提供初步的请求映射信息。相对于WEB应用的根目录;方法处:提供进一步的细分映射信息。相对于类定义处的URL。若类定义处未

    2022年5月26日
  • angular指令笔记(一):ng-options

    angular指令笔记(一):ng-options

    2022年3月7日
  • css3中的width:100vh以及calc(100vh + 10px)

    css3中的width:100vh以及calc(100vh + 10px)vh/vwvh:相对于视窗的高度,视窗被均分为100单位的vh;vw:相对于视窗的宽度,视窗被均分为100单位的vw;vmax:相对于视窗的宽度或高度中较大的那个。其中最大的那个被均分为100单位的vmax;vmin:相对于视窗的宽度或高度中较小的那个。其中最小的那个被均分为100单位的vmin;视区所指为浏览器内部的可视区域大小,即window.innerWidth/window.innerHeight大小,不包含任务栏标题栏以及底部工具栏的浏览器区域大小。calccalc是英

    2022年4月29日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号