13 core technologies of J2EE (2)

Source: Internet
Author: User
Tags perl script ibm developerworks

Source: UML software engineering organization

Java Naming and Directory Interface (JNDI)

The jndi api is used to run the name and directory services. It provides a consistent model to access and operate enterprise-level resources such as DNS and LDAP, local file systems, and the latter's objects on the application server.

In JNDI, each node in the directory structure is called context. Each JNDI name is relative to context. There is no concept of absolute name here. For an application, it can obtain its first context by using the initialcontext class:


     Context ctx = new InitialContext();

The app can use this initialized context to locate the resources or objects it needs through this directory tree. For example, suppose you expand an EJB on the WebLogic Server and bind the home interface to the MyApp name. myejb, a client of this EJB can locate the home interface through the following statement after obtaining an initialization context:


     MyEJBHome home = ctx.lookup( "myApp.myEJB" );

In this example, once you have a reference to the requested object, the EJB home interface can call the method on it. We will introduce more in the "Enterprise Java Beans" section below.

The above discussion about JNDI is just a tip of the iceberg. To further search for objects in the context, JNDI also provides some methods to perform the following operations:

Insert or bind an object to the context. This is effective when you expand an EJB.

Removes objects from context.

Lists all objects in the context.

Creates or deletes sub-level context.

Next, we will start to focus on EJB.

Enterprise Java Beans (EJB)

One of the reasons why J2EE technology has won widespread attention is EJB. They provide a framework for developing and implementing distributed business logic, significantly simplifying the development of scalable and highly complex enterprise-level applications. The EJB specification defines when and how the EJB component interacts with their containers. Containers are responsible for providing public services, such as directory services, transaction management, security, resource buffer pools, and fault tolerance.

The EJB specification defines three basic bean types:

Stateless session beans: provides a single service that does not maintain any status. It cannot continue to exist when a Server failure occurs and has a short life cycle. For example, a stateless Session Bean may be used for temperature conversion calculation.

Stateful Session Bean: T provides session interaction with the client, and stores the status to represent a customer. A typical example is shopping cart. Stateful Session Bean cannot survive when the server fails, and its life is relatively short. Each instance is used only for a single thread.

Entity beans: provide consistent data representation-typically stored in the database-can continue to exist after a Server failure occurs. Multiple users can use EJB to represent the same data. A typical example of entity EJB is the customer's account information.

Despite the above differences, all ejbs have many similarities. They all process the home interface. It defines how a client creates and destroys ejbs. You can call the remote interface that defines the client method in bean, and the Bean class executes the main business logic.

The description of EJB development is beyond the scope of this article. However, if an EJB has been developed or purchased from a third party, it must be released on the application server. WebLogic Server 5.1 comes with an EJB deployer tool to help with EJB Publishing. When using the EJB deployer tool, you need to define the JNDI name used by the client to locate the EJB. Deployer tool generates Wrapper Classes to process and communicate with containers, and binds the requested Java classes together in a jar file.

Once the EJB is published, the client can use its JNDI name to locate the EJB. First, it must get a reference to the home interface. Then, the client can use this interface to call a create () method to obtain the handle of a bean instance running on the server. Finally, the client can use this handle to call the method in the bean.

After learning about EJB, let's look at JSP.

Assumerver pages (JSPs)

Many of us may already be familiar with Microsoft's Active Server Pages (ASP) technology. JSP corresponds to ASP, but it is more platform-specific. They are designed to help Web content developers create dynamic web pages and only require a relatively small amount of code. JSP can be used even if web designers do not know how to program, because JSP applications are very convenient. A JSP page consists of HTML code and Java code embedded in it. The server processes the Java code after the page is requested by the client, and then returns the generated HTML page to the browser of the client.

Let's take a look at a simple JSP instance. It only displays the current date and time of the server. Although the syntax is beyond the scope of this article, we can intuitively see that Java code is placed in the middle of the symbol, while Java expressions are placed between symbols.

Date jsp sample

The current date is.

You may have heard of JHTML sometimes. This is an old standard of JSP. The WebLogic Server supports both JSP and JHTML. Note that by default, JSP is not in a valid state on the WebLogic Server. To make it effective, you can edit the weblogic. properties file. If the Web server is not in a valid state, make it valid first. The situation of servlet is the same as that of JSP.

Below is: Java Servlets

Java Servlets

Most of the functions provided by Servlet are similar to those provided by JSP, but the implementation methods are different. JSP usually embeds a small amount of Java code in most HTML code, while servlets is all written in Java and generates HTML.

Servlet is a small Java program that extends the functions of web servers. As a server-side application, it is executed when requested, which is similar to cgi Perl script. A major difference between servlets and CGI scripts is that each CGI requires a new process to start at the beginning -- while servlets runs in a separate thread in the servlet engine. Therefore, servlets provides good scalability improvements.

When developing Servlets, you often need to extend the javax. servlet. http. httpservlet class and override some of its methods, including:

Service (): implements the command-definition method as a dispatcher.

Doget (): process http get requests from the client.

Dopost (): performs the http post operation.

Other methods include processing different types of HTTP requests. For more information, see the httpservlet API documentation.

The above describes various methods of the standard J2EE servlet API. The WebLogic Server provides a complete way to implement this API. Once you develop a servlet, you can register it in weblogic. properties and configure it on the WebLogic Server.

Through Java Servlets, we have reached the end of main J2EE technologies. But what J2EE provides does not end with this. The following section briefly describes some existing technologies, including RMI, Java IDL and CORBA, JTA, and XML.

Remote Method Invocation (RMI)

As its name indicates, the RMI protocol calls some methods on a remote object. It uses a continuous sequence to transmit data on the client and server. RMI is a lower-layer 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 expand them in corba orb, or they can also create Java classes and serve as the customers of the CORBA objects expanded with other orb. The latter method provides another way through which Java can be used to integrate your new application with the legacy system.

Java transaction architecture (JTA)/Java Transaction Service (JTs)

JTA defines a standard API, which allows the application system to access various transaction monitoring data.

JTs is the basic implementation of the transaction monitoring function of CORBA ots. JTs specifies the implementation method of the Transaction Manager. The transaction manager is a Java image that supports the Java transaction API (JTA) specification at the high-level level and implements omg ots specification at a lower level. JTs Transaction Manager provides transaction services for application servers, resource managers, independent applications, and communication resource managers.

Javamail and JavaBeans activation framework

Javamail is an API used to access the mail server. It provides a set of abstract classes for the mail server. Not only supports SMTP servers, but also supports IMAP servers.

Javamail uses JavaBeans activation framework (JAF) to process MIME-encoded email attachments. Mime byte streams can be converted to Java objects or to Java objects. Therefore, most applications do not need to directly use JAF.

Java Messaging Service (JMS)

JMS is an application interface (API) used to communicate with message-oriented middleware ). It supports point-to-point domains, publish/subscribe domains, and supports the following types: Approved message transmission and transactional message transmission, supports consistent messages and persistent subscribers. JMS also provides another way to integrate your application with the legacy backend system.

Extensible Markup Language (XML)

XML is a language that can be used to define other Markup languages. It is used to share data in different business processes. The development of XML and Java are mutually independent. However, the same objective of XML and Java is platform independence. By combining Java and XML, you can get a perfect platform-independent solution. At present, many different companies are working hard to combine Java and XML. For more information, visit Sun's Java-XML page or IBM developerworks's XML zone.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.