JavaScript
  Home arrow JavaScript arrow Page 3 - J2EE Design Patterns: Getting Started
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

J2EE Design Patterns: Getting Started
By: A.P.Rajshekhar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 13
    2006-09-11

    Table of Contents:
  • J2EE Design Patterns: Getting Started
  • Common Design Patterns at a Glance
  • J2EE Design Patterns in the Real World
  • View component and DTO

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    J2EE Design Patterns: Getting Started - J2EE Design Patterns in the Real World


    (Page 3 of 4 )

    To implement the design patterns I will be using the solution for a Login Authentication problem. Three components implement the design patterns for this solution, which are:

    1. LoginDAO – A Java class that implements the DAO pattern.
    2. LoginController, login.jsp, welcome.jsp – The Controller and View of MVC pattern.
    3. UserDTO – A Java Bean implementing the DTO pattern and working as the Model Component.

    So let's get started.

    First we'll do the DAO implementation. The implementation provides connection services.

    package loginmodule.dao;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;
    import java.sql.Statement;
    public class LoginDAO {
    Connection connection;
    Statement statement;
    PreparedStatement pStatement;
    //First comes the connectionand statement
        public DBConnection()throws Exception {
           Class.forName("org.hsqldb.jdbcDriver").newInstance();
    connection=DriverManager
                        .getConnection("jdbc:hsqldb:hsql://localhost");//
         connection=DriverManager.getConnection
    (dbConfig.getConnectString(),dbConfig.getDbUser
    (),dbConfig.getDbPass());//
        statement=connection.createStatement();
        }
     //Then the getters and setters. It is through the getters and setters
    that //this DAO implementation provides its services
     public void setConnection(Connection connection) {
            this.connection = connection;
        }
        public Connection getConnection() {
            return connection;
        }
        public void setStatement(Statement statement) {
            this.statement = statement;
        }
        public Statement getStatement() {
            return statement;
        }
        public void setPStatement(PreparedStatement pStatement) {
            this.pStatement = pStatement;
        }
        public PreparedStatement getPStatement() {
            return pStatement;
        }   

        public void close() {
            try {
                connection.close();
            }
            catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    Next is the View implementation. It is just a JSP page providing the login and password fields for the user input.

    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html;
    harset=windows-1252"></meta>
        <title>login</title>
        <link href="css/jdeveloper.css" rel="stylesheet" media="screen"/>
        <link href="css/oracle.css" rel="stylesheet" media="screen"/>
      </head>
      <body class="APPSWINDOW"><form name="login"
    method="post"><table cellspacing="2" cellpadding="3" border="1"
    width="100%"
                                                    class="clsContentsBody">
          <tr>
            <th width="48%">
              user name
            </th>
            <td width="52%">
                <input type="text" name="user" class="GUITag"/>
              </td>
          </tr>
          <tr>
            <th width="48%">
              password
            </th>
            <td width="52%">
                <input type="password" name="passwd" class="GUITag"/>
              </td>
          </tr>
          <tr>
            <th width="48%">
              &nbsp;
            </th>
            <td width="52%">
                <input type="submit" name="submit" value="go"/>
                <input type="reset" name="reset" value="reset"/>
              </td>
          </tr>
        </table></form></body>
    </html>

    More JavaScript Articles
    More By A.P.Rajshekhar


       · Design Patterns are standard answers to recurring problems. In this discussion I...
     

    JAVASCRIPT ARTICLES

    - Comparing Fields and Customizing Error Messa...
    - Checking Numbers and File Extensions with jQ...
    - Validating Digits and Dates with jQuery`s Va...
    - Validating Ranges, Emails, and URLs with jQu...
    - More Uses for the jQuery Tooltip Plug-in`s b...
    - Building Image-Based Tooltips with the jQuer...
    - Using the jQuery Tooltip Plug-in`s bodyHandl...
    - Using Rangelength, Min and Max with the Vali...
    - Using Minlength and Maxlength with the Valid...
    - Modifying Tooltip Coordinates with the jQuer...
    - Applying a Fade Out Effect with the jQuery T...
    - Tracking Mouse Movements with the jQuery Too...
    - Checking Online Forms with the Validator jQu...
    - Nested JavaScript Functions as Objects
    - The jQuery Tooltip Plug-in







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek