Start off with Hans I loved the book.  It was extremely helpful when I
was first writing JSP/Servlet applications.  Great job!

Hans Bergsten wrote:
> EJB is overkill for most web applications, and comes at a great cost
> in terms of learning and additional implementation time. Unless you're
> very careful, it's also very easy to end up with an application with
> worse performance than if you stick to just servlets and JSP. I would
> only consider EJB if you're application has to support multiple types
> of clients (browsers, GUI apps, and other servers, for instance) and
> even then it's not a given.

This is what I thought, but having never worked with EJBs I thought I
could be wrong

> The variation of the above that I had in mind goes something like
> this. Let your Access classes use another set of classes to access
> the database. These classes encapsulate all SQL code and can return
> the data as beans that you pass on to the JSP pages. A simple example:

I like this a lot, I just have a couple questions/clarifications.

First, say I have the need to retrieve and employee from the database and
then update the information about that employee.  Would I create two
Access classes (GetEmp and UpdateEmp) or would I, should I, could I
create just one Access class (EmpRepository).  Also are the Access
classes singleton classes?
(Final question below)
>    public class EmpListAction implements Action {
>      private static final String LIST_VIEW_URL = "...";
>      private GetEmpList dao = new GetEmpList(...);
>      public String process(...) {
>        // Validation etc.
>        ...
>        EmpListBean empList = dao.getEmpList(...);
>        // Deal with null, if needed
>        ...
>        request.setAttribute(empList);
>        return LIST_VIEW_URL;
>      }
>    }
>    public class GetEmpList {
>      private DataSource ds;
Are you assuming the data source is retrieved from a JNDI lookup or
returned from a singleton class or do I actually create a separate
connection pool for each access class.

>      public GetEmpList(...) {
>        ds = ...;
>      }
>      public EmpListBean getEmpList(...) {
>        Connection conn = null;
>        EmpListBean empList = new EmpListBean();
>        try {
>          conn = ds.getConnection();
>          // Execute the SQL query and populate the bean with the result
>        }
>        catch (SQLException e) {
>          // Deal with it
>        }
>        finally {
>          if (conn != null) {
>             // Closing the Connection returns it to the pool if the
>             // DataSource is pooled
>             conn.close();
>          }
>        }
>      }
>    }
> I hope this helps.
> Hans
> --
> Hans Bergsten           [EMAIL PROTECTED]
> Gefion Software         http://www.gefionsoftware.com
> JavaServer Pages        http://TheJSPBook.com

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

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to