Java Web development technology Overview

Source: Internet
Author: User
Chapter 2 Java Web development technology Overview
The J2EE (Java 2 platform, Enterprise Edition) platform is built on j2se (Java 2 platform, Standard Edition) and provides a complete, stable, secure, and fast Java platform for enterprise-level applications. the web development technology provided by the J2EE platform mainly supports the development and application of two types of software. One is the Web application server, which is used as the advanced information system framework ), the other is the Web application running on the Web application server ).
This chapter first analyzes the J2EE architecture, and then introduces the basic concepts closely related to Java Web development technology, such as containers, components, web applications, and J2EE applications. finally, the Java Web development technology, operating principles, and various services applied at each layer of the J2EE architecture are described.
1.1 J2EE architecture
The J2EE architecture defines four different layers. The top-down direction is Client Tier, indicating the logic layer (presentation logic tier) also known as Web Tier, business tier, and data tier ).
1. Overview
As shown in J2EE architecture 1.1, front-end components that interact with end users are logically divided into customer layers, while data storage is provided. And accessFeature components are divided into data layers. on the other hand, the intermediate layer that logically resides between the frontend and the backend may consist of a logical layer and a business layer. the logical layer includes Internet-based and web-based protocols (HTTP, https, HtmlAnd XML) components that provide application functions. The business layer consists of components that capture the business logic of an enterprise. The two layers can be logically divided into two completely separated layers, each of which is independent, so that J2EE supports distributed 4-layer (or N-layer) applications. j2EE is a flexible structure that does not lock developers to a specific number of layers and does not specify the physical separation of these logical groups. in a network computing environment, a common application can run on a computer to simultaneously represent the logical layer and business layer (or even the data layer ), advanced applications can physically separate each layer on several computers.
2. J2EE applications
With the development of Web and Internet, more and more enterprises begin to develop and deploy Web-Based Enterprise intranets and external networks. J2EE provides powerful support for web-based enterprise applications.
In the web environment, the term "enterprise" describes any organization that operates according to a set of public rules. broadly speaking, "J2EE application" is only a software program specific to an enterprise. It provides certain functions based on a part of the general rules that control an organization. for example, enterprises can use J2EE to create automated purchase order processing applications, while universities can use J2EE to build a student course selection system.
J2EE architecture
The term "enterprise application" and "distributed application" have the same meaning, because every application built for an enterprise is distributed on the network in some way. "enterprise application" is another method used to describe distributed multi-layer applications, which are distributed across different layers of the organization's network infrastructure.
From the perspective of component development, J2EE supports simplified component-based development models. in this model, enterprise applications are assembled by reusing software organizations written in Java. j2EE is a fact standard for building a new distributed multi-tier application using Java, and is fully based on j2se. that is to say, J2EE actually adds a large number of enterprise-level APIs and functions on j2se to extract key elements from enterprise application development, in this way, developers can easily and effectively create a wide range of distributed applications.
At the development level, J2EE is based on the distributed multi-layer application model. in this model, application functions are logically distributed across different levels or layers of the networked computing environment. Each layer represents a set of related concepts shared by most enterprise applications. that is to say, J2EE applications are composed of software components which are grouped based on their roles in the entire application structure. J2EE components are deployed on their corresponding layers, and run in the container of the corresponding layer. containers provide standard services while enabling components AccessThe API of the corresponding layer.
Distributed multitiered application Describes software applications whose software components are distributed at different layers of the network or computing level. multi-layer structure is the core of J2EE. In a multi-layer structure, various components that constitute an application are logically separated or distributed, spanning all levels or layers of the network computing environment. multi-layer applications logically group components based on the functions that these components perform throughout the application structure. Therefore, the "layer" here indicates the logic layer or logic level of the function.
1.2 J2EE containers and components
Generally, a "Web application" can be defined Html/XML document, Java Servlet, JSP (Java Server Pages), jstl (Java Server Pages standard tag Library), classes, and any other types of files can be bundled, A collection of web resources running on multiple web containers from multiple vendors. A Web application can be moved from one server to another, or to different locations on the same server without any changes to any types of files that make up the web application.
1.2.1 container
"Container" refers to the standardized runtime environment that provides services for specific program components. With these components, you can obtain the expected services on any vendor-provided J2EE platform. the role of a container is to provide services related to Component Deployment, execution, lifecycle management, security, and other component requirements. in addition, different types of containers clearly provide additional services for various types of components they manage. for example, J2EE Web containers provide responses Customer requestTo process the request time and return the result to the running environment of the client. the J2EE container is also responsible for managing some basic services, such as the life cycle of components, sharing of database connection resources, and data persistence.
Generally, software developers only need to develop components that meet the needs of J2EE applications and install them in containers. the Installation Process of program components includes setting the parameters of each component on the J2EE application server and setting the J2EE application server itself. These settings determine the various services provided by the J2EE server at the underlying layer (for example, security, transaction management, JNDI search, and remote method calls ).
The J2EE platform defines the corresponding container types for each major component type. The J2EE platform consists of the applet container and application client container (Application client container), the Web Container ( ServletAnd JSP containers) and EJB containers (Enterprise JavaBeans container.
EJB container -- provides the runtime environment for the Enterprise JavaBean Component, which corresponds to the business layer and Data AccessLayer, mainly responsible for data processing and communication with databases or other Java programs.
Web Container -- manage JSP and ServletWeb components are mainly responsible for the communication between web applications and browsers, which correspond to the presentation layer.
Application client container-responsible for running Web applications on client components, which corresponds to the user interface layer.
Applet container-runs the Java Applet on the web browser and Java Plug-in (Java Plug-in), which corresponds to the user interface layer.
Various Java Web programming technologies are used in each container. These technologies include application component technologies (for example, Servlet, JSP, EJB and other technologies constitute the main body of the Application), application service technology (such as JDBC, JNDI and other services to ensure that components have a stable runtime environment), communication technology (such, RMI, javamail, and other technologies implement information transmission between machines and applications at the underlying platform level.
1.2.2 Components
To reduce software development costs and adapt to the rapid development needs of enterprises, the J2EE platform provides components-based design, development, assembly, and deployment of enterprise application systems. the J2EE components developed in this way do not depend on the products or APIs provided by a specific manufacturer. both developers and end users have the greatest freedom to choose products or components that can better meet business or technical needs.
1. Concept of components
A component is a software unit that enables applications to provide specific functions. components are essentially several specific Java programs, but these programs are defined with fixed formats and writing methods, and their functions and usage are standardized to a certain extent. for example, the JavaBean Component provided in Java 2 Standard Edition is a Java class file written in a specific format. you can use the getxxx () and setxxx () methods for JavaBean. AccessData in instance variables.
2. component type
The J2EE platform provides the following three types of J2EE components:
Client component-client Applet and client application.
Web components-JSP in the Web container, Servlet, Web Filter, Web event listener.
EJB component-the EJB component in the EJB container.
The relationship between components and containers is summarized as follows: components are independent software functional units assembled into J2EE applications. Each J2EE component is executed in the container, and the container provides standard services and APIs for the components, the container acts as an interface to the underlying J2EE platform. the connector resides under the J2EE platform. The connector provides APIs for porting services. J2EE applications use these APIs to insert them to existing enterprise applications. the connector is also called a resource adapter, which adds another flexibility to the J2EE architecture.
The following describes the definitions of J2EE applications from the perspective of components and containers:
A J2EE application is composed of software components. These software components are classified based on their respective layers.
The components that constitute the J2EE application are executed in the corresponding container. The Container provides a unified view of the underlying J2EE API for the component.
The container management component provides multiple system-level services for the component. for example, lifecycle management, transaction management, data caching, exception handling instance pool, thread, and security. that is to say, the J2EE application exists in the form of a distributed component set, and each distributed software component runs in its own container.
The J2EE client provides a user interface for applications. The client provides end users with a window through which end users can use various services provided by the J2EE application.
1.3 customer Layer Technology
The customer layer is used to process the customer representations and user interfaces of J2EE applications. the customer layer is represented by real-world desktop computers, Internet devices, or wireless devices. j2EE applications can be connected to a variety of client programs, including Web customers, Applet customers, and application customers.
1.3.1 web customers
Web customers are composed of browsers and web pages ( HtmlAnd XML. web pages are provided by browsers to provide end users with interfaces to access enterprise applications. various web pages provided by web customers are dynamically created by Web Components residing on the web layer. generally, the Web component that generates Web Client content is ServletAnd JSP. Web containers are responsible for managing ServletAnd JSP component execution. These components and web containers run on the J2EE server again.
The browser is responsible for correctly displaying pages to users, and does not undertake complex data retrieval and computing tasks. these complex and time-consuming operations are performed in the Web containers and EJB containers on the J2EE server. Therefore, Web customers are also called "thin customers ". the browser communicates with a specific port of the J2EE server through the HTTP protocol. browsers provide the following functions:
Display in a specific format HtmlFile.
Get the customer's click and convert it into an HTTP request ).
Connect to the Web server, send HTTP requests, and receive response ).
Manage the session state between the client and the server ).
In addition to these basic functions, it also includes some ancillary functions, such as setting users' Web security mechanisms, accessing pages and quick connections, and downloading files.
Web customers are preferred in the following scenarios:
The end users of J2EE applications reside outside the enterprise.
The end users of J2EE applications only need to use a web browser and are not easy to manage.
End users do not have to download or install any special software.
1.3.2 applet customer
Web pages generated by web layer components can contain embedded applets. applet is a lightweight client program written in Java, which is generally executed in the context of a Web browser. the applet client executed in the Web browser communicates with the web layer through the HTTP protocol. Similar to the Web Client, the applet client cannot directly AccessBusiness layer. the applet container is responsible for managing the running execution of the applet client. Generally, it is composed of a Web browser and a Java Plug-in. the advantage of Applet is that it provides a variety of graphical user interfaces that can be managed in one place. The main disadvantage is that applet is difficult to deploy, especially when the browser runs on a Java Virtual Machine embedded in different versions.
1.3.3 application customer
The application client is a Java application that is written in Java and runs on the standard JVM. The application client has full AccessCapability. You can use the swing and AWT libraries of the Java language to build complex functions and rich graphical user interfaces. different from Web customers and Applet customers, an application customer is a Java application that runs independently. It is executed in the client container instead of using a Web browser, the RMI-IIOP (Remote Method invocation, RMI; Internet Inter-ORB protocol, IIOP) protocol is used to completely interact with the EJB components at the business layer, instead of using the web layer as the intermediate media. likewise, application customers have full AccessPermission.
When selecting the Client technology, you can determine according to the specific functional requirements of the program and application scenarios.
If the web application is a general e-commerce website, using a Web browser as the client is the most appropriate choice.
If the web application requires the user to obtain information at any time, the client of the program can use wireless devices.
If a web application requires a complex and fast user interface, you should consider using an applet or a Java application that runs independently on the client. sometimes, you should also consider specific situations such as Web bandwidth requirements, response speed and security. the user's use environment also directly affects the selection of customer programs.
If Web applications require users to be able to use them on various operating systems, the standard browser and Java technology should be used as the program client whenever possible.
1.4 web Layer Technology
The web layer is responsible for handling HTTP requests and responses from thin clients. the web layer includes a standardized dynamic page generation program and a program that controls the user interface. It is an interface for end users and system programs. through interaction with the business layer, the web layer outputs the information you need in an appropriate format.
Main features of the web layer and customer Layer DifferencesFirst, the web layer mainly works on the Web server, while the user interface works on the client through a web browser. The two communicate through the Web. Second, the web layer focuses on information format processing, while the user interface is mainly convenient for people to understand and operate. for example, JSP files are compiled and run on the Web server, and information is mainly obtained from the database and transmitted to the customer. HtmlThe file is displayed on the web browser. At this time, the JSP file is on the web layer, HtmlThe page is the user interface.
1.4.1 Web Components
Web components are processing Customer requestSoftware entity, which is Customer requestCreate and return an appropriate response ( HtmlDocument or XML document ). web Components reside on the web layer and provide server-side representation capabilities for J2EE applications. standard web protocols (HTTP/https) are used to provide dynamically created content. the J2EE 1.4 Specification defines four different types of Web Components: Java Servlet, JSP, web filter, and Web event listener, as shown in Figure 1.2.
Web component Concept
The Web component runs in the Web container on the Web server. The web server can respond to the HTTP request sent by the customer, or interact with other server components as needed. in addition to direct interaction with customers, Web components can also act as an intermediate medium between Applet customers and server-side components running on the business layer and data layer. this is because the applet cannot directly AccessThe business layer and data layer must be implemented through the web layer to obtain the required functions from these two layers.
1. Java Servlet
Compared with the applet running on a browser, ServletIt is a program running on the server and written in Java. ServletIt is a protocol written in Java and a server component unrelated to the platform. ServletOn the web server. ServletAfter being loaded to the Web server and executed on JVM, no graphical user interface is required.
ServletIt provides a "request-response" Mode for client and server information processing, while Java ServletAPI defines a standard interface for processing the request and response information between the client and the server. ServletAs shown in Figure 1.3.
ServletBasic running mode
If it is static HtmlPage, the web server will process it and then generate response information.
If dynamic data is involved, the Web Server transfers the HTTP request ServletContainer processing, the result is first transmitted to the Web server, and then sent to the client browser by the Web server.
Java ServletIt has the following advantages:
Portability-web servers and application servers supported by mainstream IT vendors Servlet, So based on ServletThe solution does not restrict developers to products of a specific manufacturer. At the same time, ServletIt is written in Java, so it can run on any operating system installed with the Java Runtime Environment.
Convenience-web layer technology mainly uses HtmlPage Information, which requires the Web server to be able to read and write HTTP data headers, data bodies, process cookies, and manage sessions. ServletJava-based programming is provided. programmers can use object-oriented concepts to apply existing APIs.
Efficiency -- ServletIt is more efficient than CGI. cgi activates a process to process each HTTP request, and Web containers Use thread management. ServletResponse to HTTP requests. When a large number of customers simultaneously ServletWhen a request is sent, the Web Container only runs ServletInstead of running multiple instances as CGI, it occupies a large amount of memory. another problem with CGI is that it is cleared from memory after processing the HTTP request and cannot maintain intermediate data. while ServletMaintain the existence of the program instance in the running environment with the help of the Web container, and it will not be cleared until the Web container is stopped.
General Pricing-Java Web programming technology is currently an absolute advantage in the web server development field. ServletAnd JSP as the main technology of the web layer, its security and reliability are trustworthy. On the other hand, support ServletJSP technology has a lot of web servers. programmers can have a lot of options from the high-end oracleas 10g, Web sphere, WebLogic, To the end free tomcat.
2. jsp
JSP technology provides a simple and fast way to create a web page that displays dynamically generated content. developed by Sun, the JSP Technical Specification defines how to interact between the server and JSP, and describes the page format and syntax. JSP uses XML tags and scriptlets (a script code written in Java) to encapsulate the logic for generating page content. JSP tags in various formats ( HtmlOr XML) directly transmitted to the response page. through this transfer method, JSP achieves the separation of the page logic from its design and display. JSP is part of Java technology. JSP is compiled ServletAnd can be called with the JavaBean Component or Enterprise JavaBean Component for processing on the server side. therefore, JSP technology plays an important role in building scalable Web-based applications. like java, JSP is not limited to any specific platform or web server.
Since JSP is also compiled ServletIn theory, you can directly write ServletCreate a web application. however, JSP technology separates the page content from the display logic to simplify the process of creating a web page. in many applications, the template content and dynamically generated data must be sent to the client. based on this consideration, JSP technology is used more than all ServletMuch more convenient. JSP technology has the following main advantages:
Simple and practical -- jsp can implement most of ServletAnd inherits ServletMakes up Servlet. Jsp ServletThe Dynamic Data Processing and output formats are separated, using a similar HtmlTo facilitate the maintenance and modification of Web applications. Even if you do not understand Java programming, you can use standard labels to implement the basic functions of JSP.
Portability and good standardization -- JSP technology and Microsoft's ASP technology are competitive. JSP uses the Java language as the programming language for dynamic content generation. asp mainly uses the VBScript language. ASP programs run on Microsoft's IIS server. Once transferred from windows to other platforms, they are difficult to be used again. java has stronger applicability and portability. jsp programs can run on various platforms without modification.
ServletAnd JSP are the main technologies of the web layer. Web containers provide ServletThe runtime environment of Web components such as JSP. These components are the main channel for interaction between browsers and Web applications. ServletIt is a Java class written in Java and can be dynamically processed. Customer requestAnd construct the response. jsp based on the text. ServletIt is also executed, more suitable for creating some static content.
3. Filter
A filter is a software object residing on the web layer. ServletOr run in the JSP Container. Customer requestBy ServletOr the response created on the JSP page is dynamically transformed. ServletOr the JSP component is different, the filter does not create a response to the request, but filters the response created in advance by the web. the filtering method is to modify the response document before the response document is returned to the customer.
4. Event listener
Event Listeners are Java classes used to implement one or more ServletEvent listening interface, receiving specific
Java Web development technology Overview
Related Article

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: 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.