The largest Interview Solution Library on the web

« Previous | 1 | 2 | 3 | Next »


The most basic and necessary components of J2EE applications are
  • Servlets
  • JSPs
  • EJBs
  • Resource Adapter

A Java servlet is a Java program (a class file) that runs in the environment provided by a Java-enabled server, such as WebLogic Server. The most common use of Java servlets on WebLogic Server is to create interactive applications using standard Web browsers for the client-side presentation. WebLogic Server lets users develop and deploy business logic as a server-side process within servlets. Servlet capabilities extend from user interface (UI) generation to access databases, EJBs, messaging APIs, HTTP sessions, and other facilities exposed by WebLogic Server.

The Java servlet is simply a Java class (a file containing bytecodes) that is loaded in the Java Virtual Machine (JVM) environment on the WebLogic Server. After the servlet is loaded in the memory, one of its class methods is called to service the client request. A servlet may remain in memory for subsequent client requests and may serve multiple clients; the method is merely accessed once more, without the overhead of reloading and initializing the servlet again. This significantly improves the efficiency of the server. Figure 1-6 demonstrates the structure of a typical Java servlet, where you typically hard-code HTML tags within Java program code.

NOTE A Java servlet is a program that runs when the client requests specific information from the server. Consider a Java servlet as a server-side applet designed to work on the server and then return the information to the browser through the Web server. In much the same way that an applet extends the functionality of a browser, the Java servlet extends a server. The applet is an amazing client program, and the servlet is an amazing server program.

WebLogic Server fully supports HTTP servlets as defined in the Servlet 2.3 Specification from Sun Microsystems. HTTP servlets form an integral part of J2EE.


JSP is Sun’s specification for embedding Java with HTML to provide on-the-fly content for Web pages. When you create dynamic content, JSPs are more convenient to write than HTTP servlets because they allow you to embed Java code directly into your HTML pages, in contrast with HTTP servlets, in which you embed HTML inside Java code. JSP is part of the J2EE.

JSP enables you to separate the dynamic content of a Web page from its static counterpart. It renders services to two different types of developers: HTML developers, who are responsible for the graphic design of the page, and Java developers, who handle the development of software to create the dynamic content.

Because JSP is part of the J2EE standard, JSPs can be deployed on a variety of platforms, including WebLogic Server. In addition, third-party vendors and application developers can provide JavaBean components and define custom JSP tags, which can be referenced from a JSP page to provide dynamic content.

NOTE Java servlets and JSP reside in a special environment on the application server known as a Web container.

In which areas of applications can Java servlets and JSPs be used? Figure 1-7 delivers the concept of coding architecture of JSP, in which the Java scriptlets are embedded within HTML tags. Figure 1-8 provides a JSP example as a proof to the concept demonstrated in Figure 1-8. A Java servlet is a pure Java program written using Java Programming Language (HTML is embedded in the Java code), whereas a scriptlet is a Java code snippet that is embedded within HTML code. Servlets and JSP have inside-out architecture (exactly opposite to each other).

Areas of Application

The following shows where servlets can be applied:
  • HTML form processing This is the processing of Web-based forms, including those used to store the data to a file or package it and e-mail it to an administrator. Common Gateway Interface (CGI) scripts have conventionally performed these functions. One of the most common CGI scripts in use for this task is the form2email.cgi program. However, servlets provide better performance and scalability than CGI.
  • HTML page counters Popular additions to many Web pages, page counters can track the number of times a user has accessed a given page by incrementing a counter file somewhere on the server. Although popular, they tend to place significant overhead on the server when implemented using CGI scripts.
  • Newsgroups This is a Web-based version of the UseNet groups found on the Internet. A newsgroup is a mechanism that allows users to exchange data by leaving messages for everyone to read. These messages can also be replied to. Threads of conversations take place, in which people reply to replies.
  • Guest books A guest book is a place for guests to a Web site to leave their comments or suggestions for the webmaster. This differs from merely sending the webmaster an e-mail, as other visitors can also see the posted comments.
  • Search engines A site search engine allows the user to find information quickly and easily from within the site, without having to root around for it. Although CGI-based search engines do exist, it has been left to the built-in capabilities of the Web server to provide such functionality.
  • Banner advertising Online advertising is becoming increasingly popular with the more highly accessed sites that sell banner space to advertisers. A banner allows the advertiser to display a small image that, when clicked, will take the user to an alternative site.
  • Quote generators A quote generator is a small program that, when run, generates a new line of text. For example, UNIX fortune cookies run every time a user logs into the system, presenting the user with a new pearl of wisdom. Web-based generators operate in somewhat the same way, by inserting a new line of text into the Web page every time it is accessed.
  • Random links It is both common and courteous to have a place on a Web site that offers a list of additional places that the user may wish to visit. These lists can sometimes get very long. Instead of having the user wade through lists, webmasters can create one link that users can click to take them to a new link that’s randomly chosen from a list of possible links.
  • Chat programs Chat programs allow users to talk to each other in real time on the Internet. Internet Relay Chat (IRC) is one of the most common protocols for conversing on the Net. A separate program that runs outside the Web environment is required to use IRC (e.g., MSN Messenger or Yahoo Messenger). However, CGI was one of the tools used to bring an HTML version of IRC to the user.
Future Applications

When server-side processes are implemented using Java, a whole new world of applications can be realized. Applications that had previously required a sophisticated language solution can be easily implemented for a multiple-platform environment in Java servlets. These are listed here:
  • Advanced database accesses Providing access to databases via CGI scripts was never much of a problem; however, controlling the number of sessions and security issues sometimes was.
  • Virtual shopping baskets Virtual shopping baskets allow users to browse a site, adding items to be purchased to a list (or “cart”) as they go. Once the shopper is finished, he or she can visit the virtual checkout for payment and delivery details.
  • Online quizzes In Web-based quizzes, users answer multiple-choice questions as they race against a clock. The server must keep track of the answers as it also keeps an accurate record of the time. All this happens without users having to log into the game beforehand.
  • Dynamic images Dynamic images are generated by drawing on a virtual canvas in the server’s memory. Everything on the canvas is then converted to an image. The image can then be transmitted to the client browser via a .gif or .jpg image file.
  • Advanced HTML filters Before a Web page is delivered to a client, it can be preprocessed, removing any references to words that may be deemed unsuitable by the Web or site administrator. This process can also be extended to replace terms, as opposed to search-and-destroy–type applications.
  • Advanced HTML form processing Users have the ability to send files or data in a secure format to the server from a Web-based form.
  • E-mail transmitting servers More sophisticated e-mail distribution list applications are available. Users can sign up to receive e-mail, such as a new joke every day or a different passage from a book.
  • Site analysis In addition to providing weekly and daily statistical information regarding the number of visitors to a Web site, up-to-the-second information can be made available to site administrators. They then have the ability to see who is viewing the pages at any one point in time.
  • News feeds In broadcast systems, the user is informed of an event the second it happens, as opposed to the user having to look for the information. With news feeds, the information finds the user.

EJBs are network-aware components distributed for developing secure, scaleable, transactional, and multi-user components in a J2EE environment of WebLogic Server. These components are then deployed and rolled out on a J2EE-enabled WebLogic Server. This description describes EJBs from a functional point of view—that is, what they do. A more structural explanation would be that EJBs are collections of Java classes, interfaces, and XML files adhering to given rules.

It’s worth noting that in J2EE, all the components run inside their own containers. JSP, servlets, and JavaBeans run under Web containers. Similarly EJBs run inside an EJB container, as shown in Figure 1-9. The EJB container provides a standard set of services, such as transaction management, persistence, security, component pooling, resource management, and concurrency. EJBs are the standard for working with server-side components on Java-enabled servers. WebLogic Server has implemented the EJB architecture based on Sun’s EJB specification.

EJB Types

EJBs come in four different types:
  • Stateless session beans A stateless session bean does not maintain state between method calls. State is considered the result of a prior method call, or setting of an attribute, which is made available in a later part of the application on the Web. With stateless session beans, you cannot depend upon the result of a prior method call when making a new method call. Stateless session beans are often used to access a database or service directly where prior knowledge of events is not required or desirable. Other stateless behavior—for example, returning a list of currently logged-in users—might be modeled with a stateless session bean.
  • Stateful session beans Stateful session beans remember what happened from prior method calls. A stateful session bean may act stateless, but in most cases, it “remembers” what happened before.
  • Entity beans Entity beans, added into the EJB specification at version 1.1, are essentially stateful session beans with persistent behavior.
  • Message-driven beans Message-driven beans were added into the EJB specification with version 2.0. These are effectively stateful session beans that operate asynchronously. A message bean sits idle, waiting for a message; when one arrives, the bean processes it. Message beans can remember prior state; however, because users have no control over which particular copy of a message bean received their message (many copies of the same bean could be held in memory), prudence dictates avoiding taking advantage of state. Stateful behavior in a message bean should be constrained to reading and working with startuptype information. Message-driven beans are similar to everyday mail handlers. You drop a message into a mailbox, and a mail carrier picks it up and forwards it to someone to read. The reader may send back a message in return, but then again, she may not.
EJB Container Services

The WebLogic Server container provides certain built-in services to EJBs, which the EJBs use to function. The services that the EJB container provides are shown here:
  • Component pooling
  • Resource management
  • Transaction management
  • Security
  • Persistence
  • Concurrency
At times, EJB is used to map database entities to Java objects and encapsulate all functionality within an EJB component. These objects are then used by Java servlets that act as consumers of services that EJBs have to expose.

Resource Adapter

To understand the purpose of a Resource Adapter, you first need to know about the connector architecture. With the latest version of J2EE is a new architecture for integration of a J2EE-compliant application server, such as WebLogic with EIS. Figure 1-10 demonstrates that the central component within the WebLogic J2EE connector architecture is the Resource Adapter, which serves as the “connector.” Connector architecture enables both EIS vendors and third-party application developers to join hands and develop Resource Adapters, which can be deployed in any application server that provides support for J2EE 1.3 specifications from Sun Microsystems. Resource Adapters contain the Java components, and if necessary, also the native components Required for interacting with the EIS.

When a Resource Adapter is deployed in the WebLogic Server environment, it enables the development of robust J2EE applications that have access to a remote EIS system. Developers of WebLogic Server applications can use HTTP servlets, JSPs, EJBs, and other APIs to develop integrated applications that use the data and business logic of the EIS.
« Previous | 1 | 2 | 3 | Next »

copyright © 2014 - all rights riserved by