Java EE Third Week

Source: Internet
Author: User
Tags dname php script server memory

1. Learn about the session

1.1.session Introduction

The session is called a conversation, and the cookie saves the user-generated private data to the browser side, and the session saves the user-generated private data to the server. Note: A browser is exclusive to a session object. Therefore, when the user data needs to be saved, the server program can write the user data to the session object, when the user uses the browser to access other programs, other programs can remove the user's data from the user's session, to serve the user.

1.2 Session Principle

(1) When a session is first enabled, a unique identifier is stored in a local cookie. (2) First, using the Session_Start () function, PHP loads the stored session variables from the session repository. (3) When executing a PHP script, register the session variable by using the Session_register () function. (4) When the PHP script executes, the non-destroyed session variable is automatically saved in the session library under the local path, which can be specified by the Session.save_path in the php.ini file and can be loaded the next time the page is browsed. 1.3 UseThe Session is a Web server-based approach to maintaining state. Session allows you to persist any object during the entire user session by storing the object in the memory of the Web server. Session is typically used to perform the following actionsstores information that needs to maintain its state throughout a user's session, such as logon information or other information that a user needs to browse the Web application. stores objects that only need to maintain their state between page reloads or a set of pages grouped by functionality. the role of the Session is that it keeps the user's state information on the Web server for access at any time from a page on any device. Because the browser does not need to store any such information, it can use any browser, even if it is a browser device such as a Pad or a mobile phone. limitations of persistence methodsas more and more users log in, the amount of server memory required for the Session is increasing. Each user who accesses the Web application generates a separate Session object. The duration of each Session object is the time of the user's visit plus the time of inactivity. If you keep many objects in each session, and many users use the Web application at the same time (creating many sessions), the amount of server memory that is used for session persistence can be large, affecting scalability. 2.filter2.1 Similar to Servlets, filters are Web application components that can be bound to a Web application. But unlike other Web application components, filters are "chained" during container processing. This means that they will access an incoming request before the Servlet processor, and access the response information before the outgoing response is returned to the customer. This access allows the filter to examine and modify the contents of the request and response. Filters apply to those places.2.2 Use(1) Intercept the client's httpservletrequest before HttpServletRequest arrives at the servlet. (2) Check the httpservletrequest as needed, or modify the HttpServletRequest header and data.

(3) Intercept HttpServletResponse before HttpServletResponse arrives at the client.

(4) Check httpservletresponse according to need, can modify httpservletresponse head and data

Creating a filter takes only two steps: (1) Creating a filter processing class:
(2) Configure filter in the Web. xml file.
The Create Filter must implement the Javax.servlet.Filter interface, which defines three methods in the interface.
? void init (filterconfig config): Used to complete the initialization of the filter. void Destroy (): a collection of some resources to complete before the filter is destroyed.
void
DoFilter (ServletRequest
Request
Servletresponse

(Window.cproarray = Window.cproarray | | []). Push ({ID: "u3054369"});

Response,filterchain chain): Implements the filtering function, which is the additional processing added to each request and response.

3.async Introduction

The Async attribute specifies whether the download of the XML file should be processed synchronously.

True means that the load () method returns control to the calling program before the download is complete.

False means that the download must complete before the calling program retrieves control.

Introduction to usage examples

function Loadxmldoc (dname) {var xmldoc;//Code for Ieif (window. ActiveXObject)  {  xmldoc=new activexobject ("Microsoft.XMLDOM");  } Code for Mozilla, Firefox, Opera, Etc.else if (document.implementation && Document.implementation.createDocument)  {  xmldoc=document.implementation.createdocument ("", "", null);  } else  {  alert (' Your browser cannot handle this script ');  } xmlDoc.async=false; Xmldoc.load (dname); return (xmldoc);}

Java EE Third Week

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.