13 key technologies in J2EE [reproduced]

xiaoxiao2021-03-06  115

Steven Gould introduces 13 core technologies of Java2 Platform Enterprise (J2EE) in the text: JDBC, JNDI, EJBS, RMI, JSP, Java Servlets, XML, JMS, Java IDL, JTS, JTA, JavaMail, and Jaf. To contact reality, Gould introduces these technologies from a widely applying product environment of BEA Systems based on the WebLogic application server.

Java was originally debuted in the browser and client machine. At that time, many people question whether it is suitable for the development of the server. Now, with the increase of third parties supporting the Java2 Platform Enterprise (J2EE), Java is widely accepted as one of the preferred platforms for the development of enterprise-level server-side solutions. The J2EE platform consists of a set of services, Application Interface (APIs), and protocols that provide functional support for developing web-based multi-layer applications. In this article I will explain 13 core technologies for J2EE: JDBC, JNDI, EJBS, RMI, JSP, Java Servlets, XML, JMS, Java IDL, JTS, JTA, JavaMail, and Jaf, while will also describe when Where to use these technologies. Of course, I have to introduce how to interact between different technologies. In addition, in order to better feel the real application of J2EE, I will introduce these technologies in a WebLogic application server, a widely applying product environment from the BEA Systems. Regardless of the WEBLOGIC app server and J2EE's newcomer, it is also believed that this article must have a reference value in this article. Macro Impression: Distributed Structure and J2EE past, two-layer application - commonly referred to as Client / Server applications - is the most talkative. 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, implementing business logic, displaying results with appropriate style, popping up the preset user interface, accept user input, etc. The Client / Server structure is usually relatively easy when deploying, but it is difficult to upgrade or improve, and often based on some proprietary protocol, usually a certain database protocol. It makes it difficult to reuse business logic and interface logic. More importantly, in the web era, the second-floor apps usually cannot reflect good scalability, so it is difficult to adapt to the requirements of the Internet. The part of the SUN design J2EE is to solve the defects of the secondary structure. Thus, J2EE defines a set of standards to simplify the development of N-layer enterprise applications. It defines a standardized component and provides a complete service for these components. J2EE also automatically handles many implementation details, such as security, multithreading, etc. for applications. Developing N-layer applications with J2EE includes cutting different levels in the secondary structure into many layers. A N-layer 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. Dynamically generated display: Although the browser can complete some dynamic content display, these dynamic generated work should be made in the web server side, using JSP, Servlets, or XML (Scalable Markup Language) and Scalable style sheet language). Business logic: Business logic is suitable for implementation with Session EJBS (later will be described later). Data Access: Data Access is implemented with Entity EJBS (later later) and JDBC. Background System Integration: Integration of the same system may need to use many different techniques, as is the best need to be determined according to the characteristics of the background system. You may start surprising: Why have so many layers? In fact, multi-level approach enables enterprise-class applications with strong scalability, which allows each layer to focus on specific roles. For example, let the web server provide pages, apply the server to process the application logic, and the database server provides database services. Since J2EE is based on the Java2 Platform Standard (J2SE), all of the advantages and functions of J2SE are available.

Including "Write once, you can use" portability, access to the database through the JDBC, CORBA technology interacting with the original enterprise resources, and a validated security model. On this basis, J2EE adds support for EJB (Enterprise Java Components), Java Servlets, Java Server Page (JSPS), and XML technology. Distributed Structure and WebLogic Application Server J2EE provides a framework - a set of standard APIs for developing distributed structures, the actual implementation of this framework is left to third-party manufacturers. Some manufacturers are only focusing on specific components in the J2EE architecture, such as Apache's Tomcat provides support for JSP and Servlets, and BEA system companies provide a more complete implementation of the entire J2EE specification through its WebLogic application server products. The process of distributed and deploying distributed applications with better scalability is greatly simplified. WebLogic and J2EE have handled a lot of regular programming tasks, including providing transaction services, security areas, reliable messages, names, and directory services, database access, and connect pools, thread pools, load balancing, and fault tolerance. By providing these public services in a standard, ease of use, an application system with better scalability and maintainability is created, which provides a large number of users with increased availability. J2EE Technology In the next section, we will describe a variety of techniques that make up J2EE and how the WebLogic server is supported in a distributed application. The most commonly used J2EE technology should be JDBC, JNDI, EJB, JSP, and servlets, which we will make more careful investment. Java Database Connectivity (JDBC) JDBC API accesss a wide variety of databases in a unified manner. Like ODBC, JDBC hides the different characteristics of different databases for developers. In addition, since JDBC is based on Java, the platform independence of data inventory is also provided. JDBC defines four different drivers. The JDBC-ODBC Bridge is clearly very practical, and the JDBC-ODBC Bridge is clearly very practical, developers can use through the JDBC-ODBC bridge, developers can use JDBC to access the ODBC data source. Insufficient, he needs to install an ODBC driver on the client, in other words, a version of Microsoft Windows must be installed. Using this type You need to sacrifice the platform independence of JDBC. In addition, the ODBC driver also needs to have a client control permission. Type 2: JDBC-Native Driver Bridge JDBC Local Driver Bridge provides a JDBC interface, which is built on top of the local database driver without the need to use ODBC. The JDBC driver converts the API of the database from the standard JDBC call to local calls. With this type, you need to sacrifice the platform independence of JDBC, and also require some local code on the client. Type 3: JDBC-Network Bridge JDBC network bridge driver no longer needs a client database driver. It uses an intermediate server on the network to access the database. This application makes it possible to achieve the implementation of the technique, including load balancing, connection buffer pool and data cache. Since the third type is often only a relatively less download time, there is a platform independence, and it is not necessary to install and acquire control over the client, so it is well suited for the application on the Internet. Type 4: Pure Java Driver Quick 4 types Direct access to the database by using a pure Java database driver. This type actually implements a 2 layer structure on the client. To apply in the N-layer structure, a better approach is to write an EJB that allows it to include access code and provide a service that has database independent to the client.

The WebLogic server provides a JDBC driver for some of the usual databases, including Oracle, Sybase, Microsoft SQL Server, and Informix. It also has a JDBC driver for Cloudscape, which is a pure Java's DBMS. The WebLogic server has an assessment version of the database. Let's take an example. 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 2 fields: Name and Phone. The Cloudscape JDBC Driver is first loaded, and Driver Manager is requested to get a connection to the PhoneBook Cloudscape database. With this connection, we can construct a Statement object and use it to perform a simple SQL query. Finally, use the loop to traverse all the data of the result set, and output the contents of the Name and the Phone field with standard output. 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 Here

E.PrintStackTrace ();

}

}

}

OK. Then let's take a look at how JDBC is used in business applications. JDBC's application above in enterprise applications is actually very basic, and some may be slightly negligible. It assumes a 2-layer structure. In a multi-layer enterprise application, larger may communicate on the client and an EJB, which will establish a database connection. To achieve and improve scalability and system performance, the WebLogic server provides support for connecting buffer CONNECTION POLEL. The Connection Pool reduces the consumption of establishing and releasing database connections. Such buffer pools can be established after the system is started, and thereafter, there is a request for the database, and the WebLogic server can take the data from the buffer pool. The data buffer pool can be defined in the WebLogic.Properties file of the WebLogic server. (Refer to the example in the WebLogic.properties file, more detailed reference information in the WebLogic server document) Another common database feature in an enterprise-level application is transaction processing. The transaction is a set of statements that must be processed as the same statement to ensure data integrity. By default, JDBC uses Auto-Commit transaction mode. This can be implemented by using the setAutocommit () method of the CONNECTION class. Now we have had some understanding of JDBC, which turns to JNDI. Java Naming and Directory Interface (JNDI) JNDI API is used to perform names and directory services. It provides a consistent model to access and operate enterprise resources such as DNS and LDAP, local file systems, the latter objects in the application server. In JNDI, each node in the directory structure is called Context. Every JNDI name

It is relative to context. There is no absolute name of the absolute name. For an application, it can get its first context by using the InitialContext class:

Context ctx = new initialContext ();

Applications can locate the resources or objects they need via this initialized context. For example, suppose you expand an EJB in the WebLogic server and bind the Home interface to the name myapp.myejb, then a customer of the EJB can locate the Home interface by getting a initialization Context, you can locate the home interface:

Myejbhome Home = CTX.lookup ("MyApp.myejb");

In this example, once you have a reference to the requested object, the HOME interface of the EJB can call the method on it. We will do more in the "Enterprise Java Beans" chapters. The above discussion about JNDI is just a corner of the iceberg. If you are looking for objects to find objects in Context, JNDI also provides some ways to do the following: insert an object into or bind to Context. This is very effective when you start an EJB. Transfer objects from Context. List all objects in Context. Create or delete contexts of sub-level. Next, we have to pay attention to EJB. ENTERPRISE JAVA Beans (EJB) J2EE Technical The reason for winning some of the facts is EJB. They provide a framework to develop and implement distributed business logic, which significantly simplifies the development of enterprise applications with scalability and highly complex. The EJB specification defines how EJB components interact with their containers. The container is responsible for providing public services, such as directory services, transaction management, security, resource buffer pools, and fault tolerance. The EJB specification defines the basic bean type 3: Stateless Session Beans: Provides a single service, not maintaining any status, can not continue when the server failure occurs, the life period is relatively short. For example, a StateLess Session bean may be used to perform temperature conversion calculations. Stateful Session Bean: T provides a session interaction with the client, which can store status to represent a customer. A typical example is a shopping cart. Stateful session bean cannot continue to survive when the server fails, and life is relatively short. Each instance is only used for a single thread. Entity Beans: Provides conformance data - usually stored in the database - can continue after the server failure occurs. Multi-user can use EJB to represent the same data. A typical example of Entity EJB is the customer's account information. Although there are more differences, all EJBs have a lot of common. They all handle home interface. It defines how a client creates and demise EJB. The remote interface defined in the client method can be called; the Bean class performs the main business logic. The development of EJB has exceeded the scope of this article. However, if an EJB has been developed or purchased from a third party, it must be published in the application server. WebLogic Server 5.1 has an EJB Deployer Tool to help process the release of EJB. When you use the EJB Deployer Tool, you want to define the JNDI name used by the client to locate the EJB. Deployer Tool will generate a Wrapper class to process communication with the container and bind the requested Java class in a JAR file. Once EJB is released, the client can use its JNDI name to locate EJB. First, it must get a Reference to the home interface. Then, the client can use the interface to call a CREATE () method to get the handle of a bean instance running on the server; Finally, the client can use the handle to call the method in the bean. After learning EJB, let's look at JSP. JavaServer Pages (JSPS) We may already have many people that have been familiar with Microsoft's Active Server Pages (ASP) technology. JSP and ASP correspond to, but more platform conflict. They are designed to help web content developers create dynamic web pages and only require relatively small code. Even if the web designer doesn't know how to program how JSP is also used, JSP applications are very convenient. The JSP page is composed of HTML code and embedded Java code.

The server is processed after the page is requested by the client, and then returns the generated HTML page to the client's browser. Let's take a simple instance of JSP. It only shows the current date and time of the server. Although the specific interpretation of the grammar has exceeded the scope of this article, we can still be visually visually seen, the Java code is placed in the middle of the symbol, while Java's expression is located between the symbols. Date JSP Sample The Current Date IS. You may sometimes have heard of JHTML. This is an older standard for JSP. The WebLogic server can support JSP and support JHTML. Note that in the default situation, JSP is not active in the WebLogic server. To make it valid, you can edit the WebLogic.Properties file. If the web server is not in a valid state, you must first make it. The situation of servlet is the same as JSP. Below: The functionality provided by Java Servlets Java Servlets Servlet is similar to JSP, but the implementation is different. JSP is usually embedded in a small amount of Java code in most HTML code, while servlets are written by Java and generate HTML. Servlet is a small Java program that extends the functionality of the web server. As a server-side application, starting when the request is performed, which is similar to the CGI Perl script. A great difference between servlets and CGI scripts is that every CGI requires a new process when starting - and servlets are running in the servlet engine. Therefore, servlets provides a good improvement in scalability. When developing servlets, you often need to extend the javax.servlet.http.httpservlet class, and Override some of its methods, including: service (): as Dispatcher to implement command - definition method doget (): Hand's HTTP GET request. Dopost (): Other methods for HTTP POST also include handling different types of HTTP requests - can refer to the HTTPSERVLET API documentation. The above is described above is a variety of methods of the standard J2EE Servlet API. The WebLogic server provides a complete way of implementation of the API. Once you have developed a servlet, you can register in WebLogic.properties and thus configure it in the WebLogic server. With Java Servlets, we have reached the end of J2EE main technology. But J2EE is not allowed to be there. In the following paragraphs, we will briefly look at some of the existing technologies, including RMI, Java IDL, and CORBA, JTA, and XML, and so on. Remote Method Invocation (RMI) is as indicated by its name, the RMI protocol is called some methods on the remote object. It uses a continuous sequence to pass data on the client and server side. RMI is a lower level of protocol used by EJB. Java IDL / CORBA With the support of Java IDL, developers can integrate Java and Corba. They can create Java objects and make it expanded in Corba ORB, or they can also create Java classes and customers who are expanded with other ORBs. The latter approach provides another way, through which Java can be used to integrate your new application and Legacy system. Java Transaction Architecture (JTA) / Java Transaction Service (JTS) JTA defines a standard API, which can be accessed by various transaction monitoring. JTS is the basic implementation of CORBA OTS transaction monitoring. JTS specifies the implementation of the transaction manager.

转载请注明原文地址:https://www.9cbs.com/read-126174.html

New Post(0)