当前位置:网站首页>jsp中获取session中的值
jsp中获取session中的值
2022-06-28 19:29:00 【浪子唐少】
jsp中获取session中的值
一、后端在session中存储数据:
// username是前台传过来的用户名
User user=userService.login(username,password);
session.setAttribute(user,user);
二、前端通过EL表达式获取对应的用户名(两种方式):
1、直接通过session中的key值取得相应的value:
// user是session的key,直接获取到user数据值
// user.username是获取user数据里的username数据
<span>${user.userName }</span>
2、通过限定作用域,获取session作用域中的值
<span>${sessionScope.userName }</span>
想补充更多jsp知识的可以继续往下看:
(一)jsp有四大作用域:
page作用域 (表示当前页面) ----->pageScope (属性范围在EL中的名称)
request作用域 (表示一次客户端请求) ----->requestScope (属性范围在EL中的名称)
session作用域 (表示一次会话) ----->sessionScope (属性范围在EL中的名称)
application作用域 (表示整个Web应用的全局变量) ----->applicationScope (属性范围在EL中的名称)
通过EL表达式获取相应值的时候,第一种 ${userName } 会依序从Page、Request、Session、Application范围查找, 而第二种 ${sessionScope.userName } 会直接从Session范围查找。
(二)jsp九大内置对象:
输入输出对象:out对象、response对象、request对象
通信控制对象:pageContext对象、session对象、application对象Servlet对象:page对象、config对象
错误处理对象:exception对象
九种对象简介:
out对象:用于向客户端、浏览器输出数据。
request对象:封装了来自客户端、浏览器的各种信息。
response对象:封装了服务器的响应信息。
exception对象:封装了jsp程序执行过程中发生的异常和错误信息。
config对象:封装了应用程序的配置信息。
page对象:指向了当前jsp程序本身。
session对象:用来保存会话信息。也就是说,可以实现在同一用户的不同请求之间共享数据
application对象:代表了当前应用程序的上下文。可以在不同的用户之间共享信息。
pageContext对象:提供了对jsp页面所有对象以及命名空间的访问。
边栏推荐
- 视差js特效js轮播图插件
- How to remove dataframe field column names
- Parallax JS special effect JS carousel map plug-in
- SQL calculates daily new users and retention rate indicators
- Machine learning notes temperature+softmax
- JVM memory structure
- grafana绘制走势图
- C语言-函数知识点
- 道路千万条,为什么这家创新存储公司会选这条?
- Question brushing analysis tool
猜你喜欢

SQL calculates daily new users and retention rate indicators

Graduation project - Design and development of restaurant management game based on unity (with source code, opening report, thesis, defense PPT, demonstration video and database)

Web3 that unleashes the value of the Internet

春风动力携手华为打造智慧园区标杆,未来工厂创新迈上新台阶

pd. Difference between before and after cut interval parameter setting

变分自编码器 (Variational Autoencoders, VAEs)

How many objects are created after new string ("hello")?

团体程序设计天梯赛练习题-持续更新中

行业分析| 快对讲,楼宇对讲

Fontawesome icon for color gradient
随机推荐
论文阅读:Duplex Contextual Relation Network for Polyp Segmentation
Gaozelong, a digital economy expert: Yingke changed its name to yingcosmos. Will yuancosmos become the next growth engine of Yingke?
Are there any regular and safe foreign exchange dealers in China?
令人惊艳的NanoPC-T4(RK3399)作为工作站的初始配置和相关应用
Kaggle肠胃道图像分割比赛baseline
列表加入计时器(正计时、倒计时)
i人事HR系统上架企业微信ISV,增强企微在服务连锁零售等行业深度应用
grafana绘制走势图
春风动力携手华为打造智慧园区标杆,未来工厂创新迈上新台阶
Variational graph auto-encoders (VGAE)
PCL calculation of center and radius of circumscribed circle of plane triangle
内核错误怎么解决?Win11系统内核错误解决方法
h5向日葵作业
new String(“hello“)之后,到底创建了几个对象?
The amazing nanopc-t4 (rk3399) is used as the initial configuration and related applications of the workstation
MDM数据分析功能说明
《数字经济全景白皮书》消费金融数字化篇 重磅发布
Win11底部状态栏如何换成黑色?Win11底部状态栏换黑色的方法
Ffmpeg usage in video compression processing
R语言GLM广义线性模型:逻辑回归、泊松回归拟合小鼠临床试验数据(剂量和反应)示例和自测题