Reputation: 3175
I ask this, because on the practice assessment for my work asks a question regarding objects in JSP that have a scope of "request". Here's the question, tell me which one is the right answer:
Which of the following statements is true regarding the scope of a request in JSP?
• Objects with request scope are accessible from pages processing the same request where they were created.
• All references to the object shall be released after the request is processed; in particular, if the request is forwarded to a resource in the same runtime, the object is still reachable.
• References to objects with request scope are stored in the request object
• All of the above.
The answer is "All of the above" right? However, the answer given on the practice test says it's just the first one. But, isn't it also true that the if you forward or include the request in some other JSP or servlet, then objects of this scope are still accessible? And, isn't it also true that objects with a scope of "request" are stored in the "request object" (ie. the ServletRequest or one of its derived classes)?
Is there something else that I am missing, like maybe the objects of request scope are still accessible for some time after the request has finished being processed? Or, is there a mistake here?
Upvotes: 1
Views: 673
Reputation: 664
I think that the practice test answer is wrong. Objects such as beans are stored in the request and can be accessed with the HttpRequest object's getAttribute method. Therefore the objects live on until the end of the request.
Source: The HttpRequest/ServletRequest javadoc, and Dynamic Web Application Development using XML and Java by David Parsons, Chapter 10, which has an example that uses a request-scoped bean and forwards.
Upvotes: 1