哪个 servlet api 获取/设置请求和应用程序范围内的对象?

发布于 2024-12-20 10:08:17 字数 196 浏览 1 评论 0原文

我有点不清楚,似乎 request.getAttribute (或 setAttribute)适用于应用程序范围,即在应用程序中的所有 servlet 之间共享。

我可以在每个请求(不是会话,而是每个网络请求)范围内获取/设置某些内容吗?

例如,在过滤器中,我可能只想为此请求添加一些内容,然后在 servlet 的 doGet 中检索这些内容。

I am a bit unclear, it seems request.getAttribute (or setAttribute) is for application scope i.e. shared accross all servlets in the application.

Is there something that I can get/set on a per request (not session, but per web request) scope?

Example, in a filter, I may want to add something for this request only that I get then retrieve in my servlet's doGet.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雪若未夕 2024-12-27 10:08:17

似乎 request.getAttribute (或 setAttribute)适用于应用程序范围,即在应用程序中的所有 servlet 之间共享。

这不是真的。这仅适用于 ServletContext。您显然将其与 HttpServletRequest< /code>或误解了您当前面临的具体问题,但在您的问题中没有说明任何内容。 HttpServletRequest 实例及其所有属性绝对是请求范围的。

另请参阅:

it seems request.getAttribute (or setAttribute) is for application scope i.e. shared accross all servlets in the application.

This is not true. This is only applicable to those methods on ServletContext. You're apparently mixing it with HttpServletRequest or misinterpreting the concrete problem you're currently facing, but didn't tell anything about in your question. The HttpServletRequest instance and all of its attributes is definitely request scoped.

See also:

心凉 2024-12-27 10:08:17

“应用程序范围”是指普通的java对象和类。使用静态字段、单例等

"Application scope" mean normal java object and classes. Use static fields, singletons, e.t.c

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文