tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Re: useBean tag
Date Fri, 04 Aug 2000 03:10:56 GMT

Yes, the code is ours but you don't have control when you are planning on
integration with other products.

The idea behind having a long name (that looks like package.class) is that it
doesn't pollute the name space of the HttpSession attributes. If we just used
names like "customer", then it is quite possible that when integrating with
other web-enabled products, we may run into name clashes. This is I have used
the big long name "". This just so happens to match
the qualified package name but it need not - it just needs to be unique. If
multiple beans why required of the same class, maybe you could use a naming
convention like:

The idea is that only the bean class knows what it's name is, but by using the
qualified class name, it will be unique.

Steve. on 04/08/2000 12:55:58

Please respond to
 cc:      (bcc: Steven Shaw/Net)                              
 Subject: Re: useBean tag                                     


The bean would not be created if the bean with the same id already exists. Other
servlet may already put the bean before forwarding to your JSP. Anyway, the
is yours, you have the full control, right?

Arion wrote:

> The useBean tag seems to be less than useful when accessing session
> Say I have a bean called "" i.e. that is it's
> attribute-name set from a servlet. I then try to access the bean from a JSP
> using the useBean tag.
>      <jsp:useBean id="customerBean" .... />
> How can I do this? It seems I need something like:
>      <jsp:useBean id="customerBean" scope="session"
> name="" />
> Currently I am working around this with some code like this:
>      <% customerBean = CustomerBean.get(request); %>
> The CustomerBean.get is a static method which lazily instantiates the bean:
> public class CustomerBean {
>     private static BEAN_NAME = "";
>     public static CustomerBean get(HttpRequest request) {
>         HttpSession session = request.getSession();
>         CustomerBean bean = (CustomerBean) session.getAttribute(BEAN_NAME);;
>         if (bean == null) {
>             synchronized (session) {
>                 bean = (CustomerBean) session.getAttribute(BEAN_NAME);;
>                 if (bean == null) {
>                     bean = new CustomerBean();
>                     session.setAttribute(BEAN_NAME, bean);
>                 }
>             }
>         }
>         return careSession;
>     }
> .....
> Any comments. Am I missing something?
> cheers,
> Steve.

[This email and any files transmitted with it are confidential and may contain
information that is legally privileged. They are intended solely for the
addressee(s). Access to this email by anyone else is unauthorized. If you are
the intended recipient, please delete it and notify the sender by email
immediately; you should not copy or use it for any purpose, nor disclose its
contents to any other person. Thank you.]

View raw message