Keywords: |
J2EE |
Origin: |
Dukejava.com |
Author: Steven gocould published at: 2004.04.27
Description: Steven gocould introduces 13 core technologies of Java2 Enterprise Edition (J2EE): JDBC, JNDI, ejbs, RMI, JSP, Java Servlets, XML, JMS, java IDL, JTs, JTA, javamail, and JAF. In order to get in touch with the actual situation, gocould introduced J2EE technologies based on a widely used product environment from BEA Systems of WebLogic application server.
Java was first launched on browsers and client machines. At that time, many people questioned whether it was suitable for server-side development. Now, with the increase in third-party support for the Java2 Platform Enterprise Edition (J2EE), Java is widely accepted as one of the preferred platforms for developing enterprise-level server solutions.
The J2EE platform consists of a complete set of services, application interfaces (APIS), and Protocols. It provides Function Support for developing web-based multi-layer applications.
In this article, I will explain 13 core technologies supporting J2EE: JDBC, JNDI, ejbs, RMI, JSP, Java Servlets, XML, JMS, Java IDL, JTs, JTA, javamail and JAF will also describe when and where to use these technologies. Of course, I would also like to introduce how these different technologies interact.
In addition, to make you better feel the real applications of J2EE, I will introduce these technologies in the WebLogic application server, a widely used product environment from BEA Systems. No matter whether you are new to WebLogic application server and J2EE, or project managers and system analysts who want to know what benefits J2EE can bring, I believe this article will be of great reference value.
Macro impression: distributed architecture and J2EE
In the past, layer-2 applications-usually called client/server applications-were the most talked about. In many cases, the only service provided by the server is the database service. In this solution, the client program is responsible for data access, business logic implementation, display results with appropriate styles, pop-up preset user interfaces, and accept user input. The Client/Server structure is usually easier during the first deployment, but it is difficult to upgrade or improve. It is often based on a proprietary protocol, usually a database protocol. It makes it very difficult to reuse business logic and interface logic. More importantly, in the web era, L2 applications usually do not have good scalability, making it difficult to adapt to Internet requirements.
Part of Sun's design for J2EE is to solve the defects of the L2 structure. Therefore, J2EE defines a set of standards to simplify the development of layer-N enterprise applications. It defines a set of standardized components and provides complete services for these components. J2EE also automatically handles many implementation details for applications, such as security and multithreading.
Using J2EE to develop N-layer applications includes dividing different layers in a L2 structure into multiple layers. An N-tier application a can provide a separate layer for each of the following services:
Display: in a typical web application, the browser running on the client machine is responsible for implementing the user interface.
Dynamic generation and display: although the browser can display some dynamic content, to be compatible with different browsers, these dynamic generation tasks should be carried out on the Web server, using JSP, Servlets, or XML (Extensible Markup Language) and (Extensible style sheet language ).
Business logic: the business logic is applicable to session ejbs (which will be introduced later.
Data Access: entity ejbs and JDBC are suitable for data access.
Background system integration: the integration of the same background system may require many different technologies. The best requirements depend on the characteristics of the background system.
You may be surprised: why are there so many layers? In fact, a multi-tier approach can make enterprise-level applications highly scalable, allowing each layer to focus on specific roles. For example, the web server is responsible for providing pages and application servers to process application logic, while the database server provides database services.
Because J2EE is built on the Java 2 platform Standard Edition (j2se), it has all the advantages and functions of j2se. This includes the portability of "write once, available everywhere", the ability to access the database through JDBC, the ability to interact with the original enterprise resources, and a verified security model. Based on these, J2EE has added support for EJB (enterprise-level Java components), Java Servlets, Java Server Pages (JSPs), and XML technologies.
Distributed architecture and WebLogic application server
J2EE provides a framework-a set of standard APIs-for developing distributed architecture applications. The actual implementation of this framework is left to third-party vendors. Some vendors only focus on specific components in the entire J2EE architecture. For example, Apache Tomcat provides support for JSP and servlets, BEA System provides a complete implementation of the entire J2EE specification through its WebLogic application server product.
The WebLogic Server has simplified the process of establishing and deploying distributed applications with better scalability. Weblogic and J2EE handle a large number of common programming tasks on your behalf, including providing transaction services, security fields, reliable messages, name and directory services, database access and connection pools, thread pools, load balancing, and fault tolerance Processing.
By providing these public services in a standard and easy-to-use way, products such as WebLogic servers have created application systems with better scalability and maintainability, this increases availability for a large number of users.
J2EE Technology
In the following section, we will describe various technologies that constitute J2EE and learn how WebLogic servers support them in a distributed application. The most common J2EE technologies are JDBC, JNDI, EJB, JSP, and servlets. We will take a closer look at these technologies.
Java database connectivity (JDBC)
The jdbc api accesses a variety of databases in a unified manner. Like ODBC, JDBC hides different features of different databases for developers. In addition, because JDBC is built on Java, it also provides database access platform independence.
JDBC defines four different drivers, which are described as follows:
JDBC-ODBC Bridge Type 1
In the early stages of JDBC, The JDBC-ODBC bridge is obviously very useful, through the JDBC-ODBC bridge, developers can use JDBC to access ODBC data sources. However, you must install the ODBC driver on the client. In other words, you must install a certain version of Microsoft Windows. To use this type, you must sacrifice the independence of the JDBC platform. In addition, the ODBC driver must have the control permissions of the client.
Type 2: JDBC-native driver Bridge
The JDBC local driver bridge provides a JDBC interface, which is built on the top layer of the local database driver without using ODBC. The JDBC driver converts database APIs from standard JDBC calls to local calls. To use this type, you must sacrifice the platform independence of JDBC and install some local code on the client.
Type 3: JDBC-Network Bridge
The JDBC Network Bridge driver no longer needs the client database driver. It uses an intermediate server on the network to access the database. This application makes it possible to implement the following technologies, including Server Load balancer, connection buffer pool, and data cache. Because the 3rd types usually require less download time and platform independence, and do not require installation and control on the client, it is suitable for applications on the Internet.
Type 4: pure Java driver
The 4th types Use a pure Java Database driver to execute direct access to the database. This type actually implements a layer-2 Structure on the client. To be applied in the n-layer structure, a better way is to write an EJB that contains the access code and provides a service that is database independent to the client.
The WebLogic Server provides JDBC drivers for some common databases, including Oracle, Sybase, Microsoft SQL Server, and Informix. It also includes a JDBC driver for cloudscape, which is a pure Java DBMS and the WebLogic Server carries the evaluation version of the database.
Let's look at an instance.
JDBC instance
In this example, we assume that you have created a phonebook database in cloudscape and contain a table named contact_table, which has two fields: name and phone. First, load the cloudscape JDBC driver and request the driver manager to obtain a connection to the phonebook cloudscape database. Through this connection, we can construct a statement object and use it to execute a simple SQL query. Finally, we use a loop to traverse all the data in the result set and use the standard output to output the content of the name and phone fields.
import java.sql.*;public class JDBCExample{public static void main( String args[] ){try{Class.forName("COM.cloudscape.core.JDBCDriver");Connection conn = DriverManager.getConnection("jdbc:cloudscape:PhoneBook");Statement stmt = conn.createStatement();String sql = "SELECT name, phone FROM CONTACT_TABLE ORDER BY name";ResultSet resultSet = stmt.executeQuery( sql );String name;String phone;while ( resultSet.next() ){name = resultSet.getString(1).trim();phone = resultSet.getString(2).trim();System.out.println( name + ", " + phone );}}catch ( Exception e ){// Handle exception heree.printStackTrace();}}} |
OK. Next, let's take a look at how JDBC is used in enterprise applications.
Application of JDBC in enterprise applications
The above instances are actually very basic and may be insignificant. It assumes a 2-layer structure. In a multi-tier enterprise application, it is more likely that the client communicates with an EJB, And the EJB establishes a database connection. To achieve and improve scalability and system performance, the WebLogic Server provides support for connection buffer pool connection pools.
Connection Pool reduces the consumption of establishing and releasing database connections. After the system starts, you can create such a buffer pool. Later, if you have another request to the database, the WebLogic Server can easily retrieve data from the buffer pool. The data buffer pool can be defined in the weblogic. properties file of the WebLogic Server. (For more information, see the example in the weblogic. properties file)
Another common database feature of enterprise applications is transaction processing. Transactions are a set of declarative statements that must be processed as the same statement to ensure data integrity. By default, JDBC uses the auto-commit transaction mode. This can be achieved by using the setautocommit () method of the connection class.
Now we have some knowledge about JDBC, and we should switch to JNDI below.