servlet/jsp/jdbc best approach

Discussion in 'Java' started by Email2us, Jun 23, 2005.

  1. Email2us

    Email2us Guest

    Hello guys

    Which is the best approach when developing servlet/jsp/jdbc? I will take an
    example:

    I have index-page, page2 and page 3.

    When the user writes www.mydomain.com then the page index.jsp checks if the
    user is coming from the servlet, like this:

    <%
    if(request.getAttribute("getPageTitle")==null){
    %>
    <jsp:forward page="/Index" />
    <%
    }
    else{
    %>
    <%@ include file="/include/header.jsp" %>
    content for index.jsp
    <%@ include file="/include/footer.jsp" %>
    <%
    }
    %>

    On the other hand, the Index class has this init()

    public void init(ServletConfig config) throws ServletException {
    super.init(config);
    con = DatabaseConf.getConnection();
    }

    DatabaseConf is a class that handles all the operations related to the
    database.

    Index.class has also the doGet-method like this:

    request.setAttribute ("getPageTitle", "AnyTilte");
    getServletConfig().getServletContext().getRequestDispatcher("/index.jsp").forward(request,
    response);

    Does it looks ok so long?

    Now, I have other pages, page2 and page3 (in fact I have mych more than just
    these, but this is only an example)

    pages.jsp works as index.jsp. It makes a check
    <%
    if(request.getAttribute("getPageTitle")==null){
    %>

    if not satisfied than it redirect to

    <jsp:forward page="/Page2" />

    My concern, however, is about databasemanagement. Even the Page.class has an
    init-method that looks exactly like the one in Index.class, e.g.

    public void init(ServletConfig config) throws ServletException {
    super.init(config);
    con = DatabaseConf.getConnection();
    }

    In conclusion, Im starting jdbc-connection for every class-file that
    initiates. Is this a good approach? What I would like is a solution to
    initiate the database only one time, when the server starts. Not everytime,
    the first time a specially class-file will be called. I know, this will
    happens only one time for a file for the server's lifetime. But Im afraid
    this is not a good way to work.

    Regards

    email2us
    Email2us, Jun 23, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. circuit_breaker
    Replies:
    2
    Views:
    1,983
    Jack Jia
    Apr 4, 2004
  2. Keith Wansbrough

    Re: jdbc help:sun.jdbc.odbc.JdbcOdbcDriver

    Keith Wansbrough, Aug 16, 2004, in forum: Java
    Replies:
    0
    Views:
    733
    Keith Wansbrough
    Aug 16, 2004
  3. javadev
    Replies:
    5
    Views:
    12,862
    javadev
    Nov 16, 2006
  4. javerra
    Replies:
    11
    Views:
    654
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Feb 11, 2007
  5. Replies:
    4
    Views:
    768
Loading...

Share This Page