Showing posts with label J2EE. Show all posts
Showing posts with label J2EE. Show all posts

Wednesday, December 1, 2010

Java Design Pattern

Design Patterns are recurring solutions to design problems.

The 23 design patterns included in Design Patterns all had several known applications and were on a middle level of generality, where they could easily cross application areas and encompass several objects. These patterns are divided into 3 types.


  1. Creational Patterns: create objects for you, rather than your having to instantiate objects directly. Your programs gains more flexibility in deciding which objects need to be created for a given case.

  2. Structural Patterns: help you to compose group of objects to larger structures, such as complex user interfaces and accounting data.

  3. Behavioural Patterns: help you to define the communication between objects in your system and how the flow is controlled in a complex program.


Tuesday, November 30, 2010

MVC

MVC is a design pattern.

It contains two models. MVC Model 1 and MVC Model 2.

Struts framework implements MVC Design Pattern.
Struts can implement Model 1 and Model 2.

Model 2 most properly describes the application of MVC in a Web-Application context.
Features of MVC1 Architecture:

(1) HTML or JSP files are used to code the presentation. JSP files use java beans to retrieve data if required.
(2)MVC1 architecture is page-centric design all the business and processing logic means any JSP page can either present in the JSP or may be called directly from the JSP page.
(3)Data access is usually done using Custom tag or through java bean call.
Therefore we can say that in MVC1 there is tight coupling between page and model.

Features of MVC2 Architecture:

(1)This architecture removes the page-centric property of MVC1 architecture by separating Presentation, Control logic and Application state
(2)In MVC2 architecture there is one Controller which receive all request for the application and is responsible for taking appropriate action in response to each request.
Second one is Model which is represented by JavaBeans, business object, and database.
Third one is View or is JSP page it takes the information provided by Controller and Module and presents it to user.

Main Difference between MVC1 and MVC2:

The main difference between MVC-I and MVC-II is in MVC-I all the view,control elements are implemented using Servlets. in MVC-II the view is implemented using JSP,and the controller is implemented using Servlets,as JSP provides better user interface than Servlets

Saturday, November 27, 2010

Configuring JNDI data source in Tomcat

By using Java Naming and Directory Interface (JNDI) service, one can connect resources of different technologies.

A typical web application in Tomcat has a file called as context.xml in which the context path (root) of the web application is defined. Usually this file is located in META-INF directory of you web application (see figure 1). You can configure a JNDI data source in Tomcat by adding a declaration for your resource to this file. This is the application's context container, which enables you to specify application meta-data necessary for the server in order to deploy and run the application. There are various locations where you can specify context elements, such as your server's global i.e. tomcat-install-dir/conf/context.xml

[caption id="attachment_109" align="alignnone" width="264" caption="Figure 1: META-INF/context.xml"]context.xml[/caption]

Add the following Resource tag as a declaration for the JNDI resource. The code below is an example of how you can declare JNDI resource for MySQL database.

<?xml version="1.0"?>
<Context path="/abc">
<Resource name="jdbc/jndi-name"
auth="container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
maxWait="10000"
username="yourusername"
password="yourpassword"
driverClass="com.mysql.jdbc.Driver"
url="jdbc:mysql://hostname:3306/databasename" />
</Context>