如何在JSP和Servlet之间共享数据 [英] How to share data between a JSP and servlet

查看:74
本文介绍了如何在JSP和Servlet之间共享数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个包含servlet和JSP的网站.我想知道如何在servlet和JSP之间共享数据,因为在搜索时我注意到getSession()方法已被弃用,目前我无法将数据添加到会话中以进行共享数据.请有人建议我如何在Servlet和JSP之间共享数据.

I am developing a website with servlets and JSP.I want to know how to share data between a servlet and JSP as while searching I noticed that the getSession() method has been deprecated and currently I cannot add data to session for sharing the data.Please someone suggest me how should I share data between the servlets and JSP.

推荐答案

我们最有可能采用两种方式

We can apply two ways most probably

1)请求
2)会话

1 ) request
2 ) session

示例:

request.setAttribute("userName", userName );
session.setAttribute("userName", userName );

这篇关于如何在JSP和Servlet之间共享数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆