13 Core Technologies of Java EE (ii.)

Source: Internet
Author: User
Tags date define bind file system html page thread valid ibm developerworks
Java Naming and Directory Interface (JNDI)




The
JNDI API is used to perform name and directory services. It provides a consistent model for accessing and manipulating enterprise-class resources such as DNS and LDAP, the local file system, and the object in the application server.





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














Context ctx = new InitialContext ();













The
application can locate the resource or object it needs through the initialization context by having the directory tree. For example, if you expand an EJB in a WebLogic server and bind the home interface to the name MYAPP.MYEJB, a client of that EJB can locate the home interface with 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's home interface can invoke the method on it. We'll do more in the "Enterprise Java Beans" section below.





above the discussion of Jndi is just one corner of the iceberg. If you want to further look up objects in the context, Jndi also provides some methods for doing the following:





inserts or binds an object to the context. This is very effective when you expand an EJB.





removes objects from the context.





lists all objects in the context.





creates or deletes a child level context.





Next, we're going to start focusing on EJBS.





Enterprise Java Beans (EJB)




One of the reasons why
Java technology has won a wide attention is EJB. They provide a framework for developing and implementing distributed business logic, thereby significantly simplifying the development of scalable and highly complex enterprise-class applications. The EJB specification defines when and how EJB components interact with their containers. The container is responsible for providing common services such as directory services, transaction management, security, resource buffer pooling, and fault tolerance.




The
EJB specification defines the basic bean type in 3:





Stateless Session Beans: Provides a single service, does not maintain any state, can not continue to exist when a server failure occurs, relatively short life. For example, a stateless session bean might be used to perform temperature conversion calculations.





Stateful Session Bean:t provides conversational interaction with the client to store the state and represent a customer. A typical example is a shopping cart. The Stateful session bean cannot survive the server failure, and the life gas is relatively short. Each instance is used for only one single thread.





Entity Beans: Provides representations of consistent data--usually in a database--that can continue to exist after a server failure occurs. Multiple users can use EJBS to represent the same data. A typical example of entity EJB is customer account information.





Despite these differences, all ejbs have a lot in common. They all handle home interface. It defines how a client is created with the extinct EJB. The remote interface that defines the client method can be invoked in the bean, and the Bean class performs the primary 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 published in the application server. WebLogic Server 5.1 has an EJB deployer tool to assist in handling the release of EJBS. When you use EJB deployer tool, you define the Jndi name used by the client to locate the EJB. Deployer tool generates wrapper classes to handle communication with the container and to bind 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. The client can then use the interface to invoke a Create () method to get a handle to a bean instance running on the server and, finally, the client can use the handle to invoke the method in the bean.





understand the EJB, let's look at the JSP again.





JavaServer Pages (JSPs)





Many of us may already be familiar with Microsoft's active Server Pages (ASP) technology. JSP and ASP are corresponding, but more platform-polarized. They are designed to help Web content developers create dynamic Web pages, and require a relatively small amount of code. Even if web designers don't know how to program, they can use JSP, because JSP applications are convenient. JSP pages are made up of HTML code and embedded Java code. The server processes the Java code after the page is requested by the client, and then returns the resulting HTML page to the client's browser.





below we look at a simple example of a JSP. It shows only the current date and time of the server. Although the specific explanation of the syntax is beyond the scope of this article, we can see intuitively that Java code is placed in the middle of the symbol, while the Java expression is placed between the symbols.





Date JSP Sample





the current date is.





You may have heard of jhtml sometimes. This is an older standard that JSP used to have. The WebLogic server can support both JSP and jhtml. Note that, by default, the JSP is not in a valid state on the WebLogic server. To make this work, you can edit the Weblogic.properties file. If the Web server is not yet in a valid state, make it valid first. The servlet situation is the same as the JSP.





below are: Java servlets





Java Servlets




The
servlet provides much of the same functionality as a JSP, but it is implemented in a different way. JSP is typically a small amount of Java code embedded in most HTML code, while Servlets is written in Java and generates HTML.




The
servlet is a small Java program that extends the functionality of the Web server. As a server-side application, it is similar to a CGI Perl script to start executing when requested. A big difference between servlets and CGI scripts is that each CGI requires a new process to start at the beginning--and Servlets is running on a separate thread in the servlet engine. As a result, 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 (): Implement command-definition method as dispatcher





doget (): Handles HTTP GET requests from clients.





DoPost (): Perform an HTTP POST operation





other methods include handling different types of HTTP requests--you can refer to the HttpServlet API documentation.





The above description is a variety of methods for the standard Java Servlet API. The WebLogic server provides a complete way to implement the API. Once you have developed a servlet, you can register it in weblogic.properties and then configure it in the WebLogic server.





through the Java Servlets, we have reached the end of the main technology of EE. But this is not the end of what the Java EE offers. In the following paragraphs we will briefly look at some of the existing technologies, including RMI, Java IDL and CORBA, JTA, XML, and so on.





Remote method Invocation (RMI)





as its name indicates, the RMI protocol calls some methods on a remote object. It uses sequential sequential methods to pass data on both the client and server side. RMI is a lower-level protocol that is used by EJBS.





Java Idl/corba





with Java IDL support, developers can integrate Java with CORBA. They can create Java objects and enable them to expand in a CORBA orb, or they can create Java classes and serve as customers for CORBA objects that are expanded with other orb. The latter approach 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 from which application systems can access various transaction monitoring.





JTS is the basic implementation of CORBA OTS transaction monitoring. JTS provides a way to implement the transaction manager. The transaction manager is the Java Transaction API (JTA) specification at the top level, and the OMG OTS specification is implemented at the lower levels of the Java image. The JTS transaction Manager provides transactional services for application servers, resource managers, stand-alone applications, and communication Explorer.





JavaMail and JavaBeans activation Framework





JavaMail is an API for accessing mail servers, which provides an abstract class of mail servers. Supports not only SMTP servers, but also IMAP servers.





JavaMail uses the JavaBeans activation Framework (JAF) to process mime-encoded message attachments. A MIME byte stream can be converted to a Java object or converted from a Java object. As a result, most applications do not need to use JAF directly.





Java Messaging Service (JMS)





JMS is an application interface (API) for communicating with message-oriented middleware. It supports point-to-point domains, has domains that support the Publish/subscribe (Publish/subscribe) type, and provides support for the following types: Approved messaging, transactional message delivery, consistent messaging, and persistent subscriber support. 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 independent of each other, but it is the same goal with Java is platform independence. By combining Java and XML, you can get a perfect platform-independent solution. There are many different companies working on the combination of Java and XML at the moment. If you want to learn more about this, you can access the Sun's Java-xml page, or IBM developerworks 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.