Home arrow JavaScript arrow Page 3 - J2EE Design Patterns: Getting Started
JAVASCRIPT

J2EE Design Patterns: Getting Started


If you have been looking for a good overview of Design Patterns in J2EE, look no further. In this article you will learn about Design Patterns and how they interact with J2EE's tier-based development. It covers three of the most common Design Patterns, and provides a real-world example of Design Patterns in action.

Author Info:
By: A.P.Rajshekhar
Rating: 4 stars4 stars4 stars4 stars4 stars / 16
September 11, 2006
TABLE OF CONTENTS:
  1. · J2EE Design Patterns: Getting Started
  2. · Common Design Patterns at a Glance
  3. · J2EE Design Patterns in the Real World
  4. · View component and DTO

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

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>


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 5 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials