当前位置:网站首页>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页面所有对象以及命名空间的访问。
边栏推荐
- 国内有正规安全的外汇交易商吗?
- 从设计交付到开发,轻松畅快高效率!
- 首部元宇宙概念小说《元宇宙2086》获得2022年上袭元宇宙奖
- Month on month SQL implementation
- 释放互联网价值的 Web3
- How to resolve kernel errors? Solution to kernel error of win11 system
- Web3 that unleashes the value of the Internet
- h5向日葵作业
- 多测师肖sirapp中riginal error: Could not extract PIDs from ps output. PIDS: [], Procs: [“bad pid
- Hands on Teaching of servlet use (1)
猜你喜欢

让企业数字化砸锅和IT主管背锅的软件供应链安全风险指南

Grafana draws the trend chart

R语言GLM广义线性模型:逻辑回归、泊松回归拟合小鼠临床试验数据(剂量和反应)示例和自测题

PCL 环境下安装配置CGAL 5.4.1

Bayesian inference problem, MCMC and variational inference

NanoPC-T4(RK3399) game1 oled(I2C)显示时间天气温度

echart:横向柱状图的类目文字位置调整

There are thousands of roads. Why did this innovative storage company choose this one?

The first meta universe concept novel, meta universe 2086, won the upper attack meta universe award in 2022

论文3 VScode&texlive&SumatraPDF打造完美书写论文工具
随机推荐
视频压缩处理之ffmpeg用法
Question brushing analysis tool
List adding timer (positive and countdown)
Kettle (VI): full database backup based on kettle
PCL calculation of center and radius of circumscribed circle of plane triangle
I just bought the ADB MySQL service. Every time I do an operation, such as creating a table, this problem will pop up. What is the problem?
SQL Server2019 新建 SQL Server身份验证用户名 并登录
Live app system source code, automatically playing when encountering video dynamically
Demo of integrated development of intelligent computing system 3 plugin
Machine learning notes temperature+softmax
The amazing nanopc-t4 (rk3399) is used as the initial configuration and related applications of the workstation
Parallax JS special effect JS carousel map plug-in
多测师肖sirapp中riginal error: Could not extract PIDs from ps output. PIDS: [], Procs: [“bad pid
Find out the users who log in for 7 consecutive days and 30 consecutive days
基于趋势和季节性的时间序列预测
Double contextual relationship network for polyp segmentation
matlab 受约束的 Delaunay 三角剖分
PCL 环境下安装配置CGAL 5.4.1
How does redis implement inventory deduction? How to prevent oversold?
Group programming TIANTI competition exercise - continuously updating