Richard Yee wrote:
> Does anyone know how I might set the scope (request | session | application)
> of a Java bean from a servlet? In a JSP, I would just use <jsp:useBean
> scope=....>
>
The rules are really simple and obvious if you think about them. Here's the logic
for each of the three scopes, assuming you have created a bean called myBean and
you want to record it under the ID "myBean":
REQUEST:
request.setAttribute("myBean", myBean);
SESSION:
HttpSession session = request.getSession();
session.setAttribute("myBean", myBean);
// On pre-2.2 engines, use session.putValue("myBean", myBean);
APPLICATION:
getServletContext().setAttribute("myBean", myBean);
You will note the similarity in method names -- this is deliberate.
>
> Thanks,
>
> Richard
>
Craig McClanahan
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html