tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steven.S...@savillemail.com
Subject RE: useBean tag
Date Mon, 07 Aug 2000 02:15:19 GMT


What do you mean by "#include javax.servlet.*"





william.s.holmes.iii@lmco.com on 04/08/2000 23:38:29

Please respond to tomcat-user@jakarta.apache.org
                                                              
                                                              
                                                              
 To:      tomcat-user@jakarta.apache.org                      
                                                              
 cc:      (bcc: Steven Shaw/Net)                              
                                                              
                                                              
                                                              
 Subject: RE: useBean tag                                     
                                                              







I thought making beans include servlet information (#include
javax.servlet.*) was frowned upon.

> -----Original Message-----
> From:   Steven.Shaw@savillemail.com [SMTP:Steven.Shaw@savillemail.com]
> Sent:   Thursday, August 03, 2000 10:28 PM
> To:     tomcat-user@jakarta.apache.org
> Subject:     useBean tag
>
>
>
> 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.
>




Mime
View raw message