2016-09-06 the basic knowledge of the Java EE

Source: Internet
Author: User
Tags microsoft iis

1. Middleware, containers, Web servers

1.1 Middleware

Middleware is the software that provides the connection between the system software and the application software , so as to communicate between the parts of the software. Middleware is between the operating system and the higher-level application.

The background of the Java EE proposed:

1) Requirements of enterprise Application framework: In many enterprise applications, such as database connection, mail service, transaction processing and so on are some common enterprise requirement modules, each time the development of these modules is done by the developer, it will lead to the problem of long development cycle and poor code reliability. Many large companies have developed their own generic module services, which are called middleware.

2) General specifications: Because these middleware and user communication are different, so that users can not assemble it for their own services, and then put forward the concept of standard, Java is based on a series of standards.

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

Commercial Middleware Main camp: Microsoft Camp, Java camp, open source camp.

Common middleware: Apache-tomcat, Ibm-websphere, Bea-weblogic, Kingdee-apusic

1.2 Containers

a container is a middleware that acts as a middleware role.

Classification of containers:

1) Web Container

Provides an environment (JSP container and Servlet) for the application component (Jsp,servlet) in which the component (Jsp,servlet) interacts directly with the environment variable interface in the container. The interface provided by the container strictly complies with the Web application standard in the Java EE specification, and we put the above standard Web server called the Java EE Web container.

2) EJB Container

Enterprise Java Bean container. It provides various management functions to the components running in it Ehb. As long as the EJB that satisfies the Java EE specification is put into a container, it is quickly managed by the container and gets system-level services through the thread's interface, such as mail service, transaction management, etc.

3) The difference between a Web container and an EJB container

Web containers and EJB containers are largely the same in principle, and they all interact with the outside world to ease the burden on the application.

The main difference is the isolated external environment. The web container interacts primarily with HTTP-based requests, and the EJB container interacts primarily with databases and other services. If the servlet is concerned with the details of HTTP, directly referencing the environment variable SESSION,REQUEST,RESPONSE;EJB does not care about the database connection speed, various transaction control, directly by the EJB container to complete.

1.3 Web server (program/software)

A program that provides web information browsing services that provide services to a customer's browser

1) Current common Web server:

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

Small: Nginx, micro_httpd, mini_httpd, thttpd, LIGHTTPD, shttpd

2) Application server supporting the Java EE:

WEBSPHERE, WEBLOGIC, JBOSS, ORACLE application Server, SUN one application server, and more.

2.ServletContext Functional Effect

2.1 ServletContext

1) is a global storage space for information, the server starts, it exists, the server shuts down, it is released, all users share a ServletContext.

2) A ServletContext object represents the context of a Web application, is the root of a known path in the Web server, in order to save space, improve efficiency, servletcontext, to put the necessary, important, The threads that all users need to share are also some information that is secure.

2.2 Servlet Context

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

For example, to do a shopping site, to extract information from the database, if the session to save these items information, each user access to a database, the efficiency is too low; So to use the servlet context to save, at the beginning of the server, access to the database, Store the item information in the servlet context so that each user can only read the item information from the context.

2) sErvlet You can bind an object property to a context by name . any property 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 functionality:

SetAttribute

GetAttribute

Getattributenames

RemoveAttribute

Context properties are local to the VM that created them. This prevents the ServletContext property 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 placed in a session (see Chapter 7th, "Sessions"), stored in a database, or stored in an EJB component .

3) ServletContext Interface

The ServletContext interface defines the servlet view of the Web app that runs the servlet. Using the ServletContext object, the servlet can record the event log, get the URL address of the resource, and set and save the properties of other servlets that can be accessed within the context.

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

4) Initialization parameters

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

Getinitparameter

Getinitparameternames

The application developer takes advantage of the initialization parameters to transfer configuration information. A typical example is a Web administrator's e-mail address or a system name that holds critical data.

3.HTTP session

Maintaining a session is maintained between HTTP connections that maintain the association of users with different requests made by the unified user.

3.1 Characteristics of the session

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

2) Once a session is established, it should persist until the user's idle time exceeds a certain time limit and the container should release the session resource

3) during the lifetime of the session, the user may send a lot of requests to the server, and the user's request information can be stored in the session

3.2 Establishment Process

1) Establish a TCP connection
2) issuing the request document
3) Send a response document
4) Release the TCP connection

The difference between 4.GET and POST request mode

4.1 Get method

Using the GET Request method, the query string is concatenated with a key-value pair to the server after the URL is sent.

Get method Features:

1) Get request can be cached;

2) Get requests are mainly used to obtain data;

3) The length of the GET request is limited;

4) The GET request is saved in the browser's history;

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

6) The requested data is appended to the URL, to split the URL and transfer data, multiple parameters with & connection. The URL is encoded in ASCII encoding instead of Uniclde, which means that all non-ASCII characters are encoded before being transmitted

4.2 Post Method

Depending on how the post is requested, the query string exists separately in the POST request and is sent to the server along with the HTTP request.

Post Method Features:

1) Post request cannot be cached

2) Post requests are not saved in browser browsing history

3) URL with POST request cannot be saved as browser bookmark

4) Post request has no length limit

4.3 get vs. Post differences

GET POST
Click the Refresh or Return button No impact Re-send data
Add Bookmark Cannot be added can add
Cache No cache exists Cache exists
Historical records There is a history record There are no history records
URL length limit There is a length limit No length limit
Encoding type application/x-www-form-urlencoded

application/x-www-form-urlencoded or Multipart/form-data

If you are transmitting binary data, you need to set multipart encoding for it

Transfer data type Only ASCII character type allowed No limit, can be a binary type
Security Do not submit sensitive data in Get mode To transmit sensitive data, encrypt
Query string Visibility Visible Not visible

5.Servlet forwarding and redirection

Response.sendredirect ("a.jsp");--forwarding; Request.getrequestdispatcher ("a.jsp"). Forward (Request,response)--redirect

Difference:

1) forwarding is done on the server side, and redirects are done on the client

2) The same request is forwarded; REDIRECT is two different requests

3) forwarding does not execute post-forwarding code; REDIRECT executes code after redirection

4) The forwarding browser address bar does not change, reset the browser to the address bar changes

5) forwarding must be done under the same server; redirection can be done under different servers

2016-09-06 the basic knowledge of the Java EE

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.