tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Arion Yu <ario...@stt.com.hk>
Subject Re: useBean tag
Date Fri, 04 Aug 2000 02:55:58 GMT
Hi!

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 program
is yours, you have the full control, right?

Arion

Steven.Shaw@savillemail.com wrote:

> The useBean tag seems to be less than useful when accessing session attributes.
> Say I have a bean called "com.foo.beans.CustomerBean" 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="com.foo.beans.CustomerBean" />
>
> 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 = "com.foo.beans.CustomerBean";
>
>     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 not
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.]



Mime
View raw message