tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bryan Basham <>
Subject RE: Sessions and absolute URLs
Date Tue, 12 Dec 2000 22:32:17 GMT

> OK - I'll try that. Excuse the lack of knowledge,
> but is it possible to access a bean from a servlet
> (not a jsp)?

There is a rough equivalence between JSP bean "scopes" and servlet code:

  * <jsp:useBean id="name" class="..." scope="page"/>
    servlet equiv. is a local variable in the doXyz (e.g. doGet) method

  * <jsp:useBean id="name" class="..." scope="request"/>
    <class> name = (<class>) request.getAttribute("name")

  * <jsp:useBean id="name" class="..." scope="session"/>
    HttpSession session = request.getSession();
    <class> name = (<class>) session.getAttribute("name")

  * <jsp:useBean id="name" class="..." scope="application"/>
    ServletContext context = getServletContext();
    <class> name = (<class>) context.getAttribute("name")

You can set the bean in a servlet by using an equivalent setAttribute
method (except for "page" scope).  This allows servlets to set beans
that are then may be used by JSP pages.


View raw message