Connecting: 13 core technologies for J2EE (1) 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.