I do not know basic J2EE knowledge, 2016-09-06j2ee

Source: Internet
Author: User
Tags microsoft iis

I do not know basic J2EE knowledge, 2016-09-06j2ee

1. middleware, containers, and Web Servers

1.1 Middleware

Middleware is the software that provides the connection between system software and application software, so as to facilitate communication between various software components. Middleware is located between the operating system and higher-level applications.

Background of J2EE:

1) requirements for enterprise-level application frameworks: In many enterprise-level applications, such as database connections, email services, and transaction processing, these are common enterprise requirement modules, if the development of these modules is completed by developers, the development cycle and code reliability may be poor. As a result, many large companies have developed their own general module services. These service-type software series are called middleware.

2) General Specifications: because these middleware and user communication are different, users cannot assemble the middleware to serve themselves. Therefore, the standard concept is proposed, j2EE is a series of standards based on JAVA technology.

Middleware: isolates the application running environment from the operating system, so that application developers do not have to worry about more system problems, but directly focus on the application's ability to solve problems.

Major commercial middleware camp: Microsoft camp, Java camp, and open source camp.

Common middleware: Apache-Tomcat, IBM-WebSphere, BEA-WebLogic, Kingdee-Apusic

1.2 containers

A container is a type of middleware that acts as a middleware.

Container category:

1) Web Container

An environment (JSP Container and Servlet) is provided for the application components (Jsp and Servlet) in the container. The JSP and Servlet components directly interact with the environment variable interface in the container. The interfaces provided by containers strictly abide by the web application standards in the J2EE specification. We call the above standard WEB server a J2EE WEB container.

2) EJB container

Enterprise java bean container. It provides various management functions for the component EHB running in it. As long as the ejbs meeting the J2EE specifications are put into the container, they will be managed efficiently by the container immediately, and system-level services such as mail service and transaction management will be obtained through the thread interface.

3) Differences Between Web containers and EJB containers

WEB containers and EJB containers share the same principle. They both allow external interactions to ease the burden on applications.

The main difference is the isolated external environment. The WEB Container interacts with HTTP requests, while the EJB container interacts with databases and other services. For example, Servlet directly references the environment variables session, request, and response for different HTTP details. EJB does not need to care about the database connection speed and various transaction controls, and is directly completed by the EJB container.

1.3 WEB Server (Program/software)

Programs that provide Web information browsing services and services to customers' browsers

1) common web servers:

Large: Microsoft IIS, IBM WebSphere, BEA WebLogic, Apache, Tomcat

Small: nginx, micro_httpd, mini_httpd, thttpd, lighttpd, Shttpd

2) J2EE-supported application servers:

WEBSPHERE, WEBLOGIC, JBOSS, oracle application server, and sun one application server.

2. Functions of ServletContext

2.1 ServletContext

1) It is a space for storing information globally. It exists at the beginning of the server, and is released only when the server is closed. All users share a servletContext.

2) A ServletContext object represents the context of a Web application and is the root of a known path in the Web server. To save space and improve efficiency, in ServletContext, it is safe to put necessary and important threads that all users need to share.

2.2 Servlet context

1) provide access to the various resources and functions of all servlets in the application. The Servlet context API is used to set information that is common to all servlets in an application. Servlet may need to share the common information between them. Servlets running on the same server sometimes share resources, such as JSP pages, files, and other servlets.

For example, a shopping website needs to extract item information from the database. If session is used to save the item information, every user can access the database, which is too inefficient; therefore, it is used to store Servlet context. When the server starts, it accesses the database and stores the item information in the Servlet context. In this way, each user only needs to read the item information from the context.

2) servlet can bind object attributes to the context by name. Any attributes bound to the context can be used by other servlets of the same web application. The following methods of the ServletContext interface allow access to this function:

SetAttribute

GetAttribute

GetAttributeNames

RemoveAttribute

Context attributes are local for the VMS that create them. This prevents the ServletContext attribute from being stored in the shared memory of the distributed container. When information needs to be shared between Servlets running in a distributed environment, the information is stored in the session (see chapter 7th "session"), stored in the database, or in the EJB component.

3) ServletContext Interface

The ServletContext interface defines the servlet view of the web application running servlet. Using the ServletContext object, servlet can record event logs, obtain the URL address of the resource, and set and save attributes of other servlets that can be accessed in the context.

Each web application deployed in the container has an instance object associated with the ServletContext interface. If the container is distributed across multiple virtual machines, a web application will have a ServletContext instance in each VM.

4) initialization parameters

The initialization parameters of the ServletContext interface allow the servlet to access the context initialization parameters related to the web application, which are specified by the application developer in the deployment descriptor:

GetInitParameter

GetInitParameterNames

Application developers use initialization parameters tO Send configuration information. A typical example is the e-mail address of the web administrator or the name of a system that holds key data.

3. HTTP session

Maintaining the association between users and different requests issued by unified users between HTTP connections is called maintaining a session ).

3.1 session features

1) sessions of different users should be independent of each other

2) A session should exist until the user's idle time exceeds a certain time limit, and the container should release the session resource.

3) during the session survival period, the user may send many requests to the server. The user's request information can be stored in the session.

3.2 creation process

1) Establish a tcp connection
2) Send request documents
3) Send response documents
4) release the tcp Connection

4. Differences between GET and POST requests

4.1 GET Method

Using the GET request method, the query string is connected by a key-value pair after the URL and is transmitted to the server together.

Features of the GET method:

1) GET requests can be cached;

2) GET requests are mainly used to obtain data;

3) The length of the GET request is limited;

4) GET requests are stored in the browser's historical records;

5) the URL of the GET request can be saved as a bookmarks.

6) The requested data will be appended to the URL? Splits the URL and transmits data. Multiple parameters are connected. The URL encoding format uses ASCII encoding instead of uniclde, that is, all non-ASCII characters must be encoded before transmission.

4.2 POST Method

The query string exists independently in the POST request and is sent to the server together with the HTTP request.

POST method features:

1) POST requests cannot be cached

2) POST requests are not stored in browser browsing records

3) The URL requested by POST cannot be saved as a browser bookmarks

4) the POST request has no length limit.

4.3 difference between GET and POST

  GET POST
Click Refresh or return. No effect Resend data
Add bookmarks Cannot add You can add
Cache No cache exists Cache exists
History History No history exists
URL length limit Length limit No length limit
Encoding type Application/x-www-form-urlencoded

Application/x-www-form-urlencoded or multipart/form-data

If binary data is transmitted, you need to set multipart encoding for it.

Transfer Data Type Only ASCII character type is allowed No limit. It can be of binary type.
Security Do not use GET to submit sensitive data Encrypt Sensitive Data Transmission
Query string visibility Visible Invisible

 

 

 

 

 

 

 

 

 

 

5. Servlet forwarding and redirection

Response. sendRedirect ("a. jsp"); -- forward; request. getRequestDispatcher ("a. jsp"). forward (request, response) -- redirect

Differences:

1) The forwarding is completed on the server side, and the redirection is completed on the client side.

2) the same request is forwarded, And the redirection is two different requests.

3) The forwarded code is not executed, and the redirected code is executed.

4) the address bar of the forwarding browser has not changed; the browser has changed to the address bar.

5) The forwarding must be completed under the same server; the redirection can be completed under different servers.

 

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