Skip to Content
Node与Express开发(第2版)
book

Node与Express开发(第2版)

by Ethan Brown
June 2021
Intermediate to advanced
290 pages
9h 21m
Chinese
Posts & Telecom Press
Content preview from Node与Express开发(第2版)
Cookie
和
Session
|
95
cookie
Session
所使用的
Cookie
的设置(
path
、
domain
、
secure
,等等)。默认使用常规
Cookie
的设置。
9.4.2
 使用
Session
一旦把
Session
设置好,使用起来就再简单不过了,直接使用
request
对象的
session
变量
中的属性:
req.session.userName = 'Anonymous'
const colorScheme = req.session.colorScheme || 'dark'
注意对于
Session
,不需要分别使用
request
对象获取值,使用
response
对象设置值,都是
在
request
对象上操作的
(
response
对象并没有
session
属性)。要删除一条
Session
数据,
可以使用
JavaScript
的
delete
操作:
req.session.userName = null // 把userName设置为null,但并不移除它
delete req.session.colorScheme // 移除colorScheme
9.5
 使用
Session
实现
flash
消息
flash
消息(不要跟
Adobe
的
Flash
相混淆)只是向用户提供反馈的一种方式
,不会影响用
户的页面导航。要实现
flash
消息
,最简单的办法就是使用
Session
(你也可以使用查询串,
但这样会让
URL
更
难看,而且当用户添加书签的时候,这个消息也会包含在书签里,这些
应该是你不想看到的)。先从
HTML
开始。
我们将使用 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

面向对象的思考过程(原书第5版)

面向对象的思考过程(原书第5版)

马特 魏斯费尔德
精通模块化JavaScript

精通模块化JavaScript

Nicolás Bevacqua

Publisher Resources

ISBN: 9787115565099