Brian Burridge wrote:

> Is there a method that you can use on a JSP session bean to get a list
> of all the variables?
>
> I tried using session.getValueNames(), but that only gives me the bean
> name itself (and the associated id as the value). I don't want the
> variables in the servlet session, I want a list of all the variables
> (and values) that I've stored in my JSP session bean.
>

What about something like this:

    Enumeration names = session.getValueNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        Object bean = session.getValue(name);
        System.out.println("Session bean '" + name + "' has value '" +
            bean.toString());
    }

(In a 2.2 servlet container, you would replace getValueNames() by
getAttributeNames() and getValue() by getAttribute() -- these names were changed
for consistency with the other scopes.)

Obviously, you can do anything else with all of the values that you need.  The same
concept applies to request attributes and servlet context attributes -- in each
case, you can get an enumeration of the names, and therefore have access to all the
values.

Craig McClanahan

===========================================================================
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