You are on page 1of 31

J2ee

Architecture
‫أبيسلّوم‬
ّ .‫قم‬.‫إعداد م‬

1
• The expectation for instant gratification was ratcheted up a notch with the
growth of the Internet.

• Many IT departments used a two-tier, client/server.

• Two-tier architecture depends heavily on keeping client software updated.

• Web-based multi-tier systems don’t require client software to be upgraded


whenever presentation and functionality of an application are changed.

• Java programming language is used to build software for this new multi-tier
architecture.

2
• A group of technologies that provide one or more services to
its clients.

• A component is part of a tier that consists of a collection of


classes or a program that performs a function to provide the
service.

• A container is software that manages a component and


provides a component with system services.
o A container handles resource management, security, threading, and
other system-level services

3
4
Java 2 Platform, Enterprise Edition (J2EE)
Multi-Tier Architecture
• J2EE is a four-tier architecture

• The Web Tier provides Internet functionality to a J2EE


application.

• Components that operate on the Web Tier use HTTP to receive


requests from and send responses to clients.

5
.Cont
• There are two types of components that work on the Web Tier.
These are servlets and JavaServer Pages (JSP).

• The Enterprise JavaBeans Tier automatically handles


concurrency issues that assure multiple clients have
simultaneous access to the same object.

• EIS tier contains data base management system(DBMS) that


manages database issues(create, insert,update,………).

6
7
Servlets

• Classes on the servrer side that dynamically process requests and


construct responses
o Dynamically generate html pages in response to requests

• A servlet stays in memory, so it doesn’t have to be reloaded


each time

• There is only one instance handling multiple requests, not a


separate instance for every request.

8
GlassFish
• GlassFish is a very popular server

•It’s best to think of GlassFish as a “servlet container”.

• GassFish is:
o Efficient
o Secure
o Up to date with current standards
o Open source
o Free

9
Ports
• A port is a connection between a server and a client
o Ports are identified by positive integers
o A port is a software notion, not a hardware notion, so there may be
very many of them
• A service is associated with a specific port
o Typical port numbers:
• 21—FTP, File Transfer Protocol
• 22—SSH, Secure Shell
• 25—SMTP, Simple Mail Transfer Protocol
• 53—DNS, Domain Name Service
• 80—HTTP, Hypertext Transfer Protocol These are the ports
• 8080—HTTP (used for testing HTTP) Glassfish of most interest to us
• 7648, 7649—CU-SeeMe
• 27960—Quake III

10
Writing a Servlet
• Create a servletclass
o extend HttpServlet
• Implement the doGet() or doPost() method
o Both methods accept two parameters
 HttpServletRequest
 HttpServletResponse
o Obtain parameters from HttpServletRequest Interface using
 getParameter(String name)
o Obtain the writer from the response object
o Process input data and generate output (in html form) and
write to the writer
o Close the writer

11
Response from server to client
• Everything sent via the Web has a “MIME type”

• The first thing we must do with response is set the MIME


type of our reply: response.setContentType("text/html");
o This tells the client to interpret the page as HTML

• Because we will be outputting character data, we need a


PrintWriter, handily provided for us by the getWriter
method of response:
PrintWriter out = response.getWriter();

12
Getting the parameters
• Using reguest object in doGet method

• Reguest. getParameterNames()
 Returns an Enumeration of the parameter names
• Reguest. getParameter(String name)
 Returns the value of the parameter name as a String
• Reguest. getParameterValues(name)
 Returns an array of values of the parameter name

13
14
Servletclass (at the server side)

15
Index.html

16
JDBC

• JDBC stands for Java Database Connectivity, which is a


standard Java API for database independent connectivity
between the Java programming language, and a wide range of
databases.

• The JDBC provides several tasks:


o Making a connection to a database.
o Creating SQL or MySQL statements.
o Executing SQL or MySQL queries in the database.
o Viewing & Modifying the resulting records.

17
JDBC Architecture
• JDBC API: This provides the application-to-JDBC Manager
connection.

• JDBC Driver API: This supports the JDBC Manager-to-


Driver Connection.

18
19
MySQL

• MySQL is a popular Open Source relational database


management system (RDBMS) commonly used in web
applications
due to its:

o speed
o flexibility
o reliability.

• MySQL employs Structured Query Language, for accessing


and processing data contained in databases.
20
Basic Steps in Using JDBC

1. Load the driver


2. Define the Connection URL
3. Establish the Connection
4. Create a Statement object
5. Execute a query
6. Process the results
7. Close the connection

21
JDBC Step 1: Load the Driver
try {
Class.forName ("com.mysql.jdbc.Driver");
Class.forName ("oracle.jdbc.driver.OracleDriver");
}
catch (ClassNotFoundException cnfe) {
System.out.println("Error loading driver: " + cnfe);
}

22
JDBC Step 2: Define the Connection URL
Examples:

String host = "dbhost.yourcompany.com";


String dbName = "someName";
int port = 3306;
String mySqlUrl = "jdbc:mysql://" + host + ":" + port +
"/" + dbName;

23
JDBC Step 3: Establish the Connection
• Connection connection = DriverManager.getConnection
(mySqlUrl, username,password);

JDBC Step 4: Make a Statement

• Statement statement =connection.createStatement();

24
JDBC Step 5: Execute a Query

String query = "SELECT col1, col2, col3 FROM sometable";

ResultSet resultSet = statement.executeQuery (query);

25
JDBC Step 6: Process the Result
• resultSet.next()
o Goes to the next row. Returns false if no next row.

• resultSet.getString("columnName")
o Returns value of column with designated name in current
row, as a String. Also getInt, getDouble, etc.

JDBC Step 7: Close the Connection

• connection.close();

26
.Start your MySQL server
• MySQL server is running on port 3306 (whereas the GlassFish
is running on port 8080).

o cd \”path to mysql”\bin
o mysqld --console

• Start a MySQL client.


o mysql -u root -p

27
The software used
Version Software

8.2 NetBeans IDE(including


ClassFish)
8 Java Development Kit (JDK)

5.7.21 MySQL database server

5.1.45 mysql-connector-java

28
Download mysql
• Download MySQL ZIP ARCHIVE from
https://dev.mysql.com/downloads/mysql/:
A. Choose "General Available (GA) Releases" tab.

B. Under "MySQL Community Server 5.7.xx" ⇒ In "Select


Platform", choose "Microsoft Windows".

C. Under "Other Downloads", download "Windows (x86, 64-bit),


ZIP ARCHIVE (mysql-5.7.xx-winx64.zip)" or "Windows (x86,
32-bit), ZIP ARCHIVE (mysql-5.7.xx-win32.zip)".

D. There is NO need to "Login" or "Sign up" - Just click "No


thanks, just start my downloads!".

29
Download mysql connectors

• Download the "latest" MySQL JDBC driver from


http://dev.mysql.com/downloads ⇒ "MySQL Connectors" ⇒
"Connector/J" ⇒ Connector/J 5.1.{xx} ⇒ select "Platform
Independent" ⇒ ZIP Archive (e.g., "mysql-connector-java-5.1.
{xx}.zip", where {xx} is the latest release number) ⇒ "No thanks,
just start my download".

30
31

You might also like