[ March 19, 2007: Message edited by: Joseph Sweet ]
We must know, we will know. -- David Hilbert
posted 11 years ago
I don't understand your last message...
Request scope is shared across all resources participating in the request. This can include any servlet controller that might have gained control prior to the JSP -- a very common pattern to employ -- and (with a bit of hand-waving) any included JSPs.
Not sure what you mean by a servlet controller and how it gains control over the JSP..
Within one request/response cycle the context can be passed between multiple servlets and/or jsp with requestDispatcher.forward(resource) or with the jsp:forward action. MVC apps always separate the various concerns by having a servlet receive the request, create java objects and call their methods to perform the business logic, and then forward to the JSP for formatting.
In a case such as this, beans generated in the servlet can be bound to request scope to be made available to the JSP.
From within a servlet, you will add you bean/object to the appropriate scope(request, session,etc) with setAttribute() as in request.setAttribute(yourObjectsName, yourobject). Then within your JSP it will be accesed from the appropriate scope. For obvious reasons, the page scope does not exist for a servlet.
Originally posted by Joseph Sweet: Thank you for the article.
So I have a way to instantiate beans in a JSP and define their scope to be the request's scope.
How do I define the scope from within a servlet?
Bosun (SCJP, SCWCD).
So much trouble in the world -- Bob Marley