Any object can be stored as an accessible bean, if you do it yourself.  In other
words, you can create a Hashtable (in a servlet or JSP page) and store it in the
appropriate place, then access it with <jsp:useBean> declarations.  For example,
you can do the following (in a servlet or a JSP scriptlet) to put a Hashtable into
the user's session:

    Hashtable mytable = new Hashtable();
    HttpSession session = request.getSession();
    session.put("hashtable", mytable);

and then access it in JSP like this:

    <jsp:useBean id="hashtable" class="java.util.Hashtable" scope="session"/>

If you want the <jsp:useBean> tag to create the bean if its not there, your Java
class needs to conform to the naming conventions in the JavaBeans spec.  For the
purposes of <jsp:useBean>, the critical rule is that your class must have a
no-arguments constructor.  Many (but not all) classes have this feature, and are
thus suitable for use in this way.

Craig McClanahan


Frank Kim wrote:

> Is there a way to access data in a Hashtable from a JSP or does data always
> have to be exposed through a bean?
>
> I'd like to use it like a context in WebMacro or a SimpleHash in FreeMarker
> where the Hashtable can store simple types as well as complex ones like
> other Hashtables, Vectors, etc.
>
> Thanks
> Frank
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to