codecompleting
codecompleting

Reputation: 9611

Which servlet api gets/sets objects in request and application scope?

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.

Upvotes: 0

Views: 1366

Answers (2)

korifey
korifey

Reputation: 3509

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

Upvotes: 0

BalusC
BalusC

Reputation: 1108642

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:

Upvotes: 3

Related Questions