Cookie session URL rewrite and exam

Source: Internet
Author: User

state Management, Cookie,Session,URL rewrite

HTTP protocol: Stateless connection (each connection is a new request)
1, hidden field <input type= "hidden" name= "session" value= "/> In response operation
2. Cookies are saved to the client
3. Session Save to server
4. User-disabled cookie: Use URL rewrite to add jsessionid=123 after URL;

Cookie principle
1, the data in the form of "key-value" to save in response to the client
Cookie cookie = new Cookie ("", "");
Response.addcookie (cookie);
Expiry time: At the end of a session
A browser saves cookies; A browser can construct multiple cookies
Read cookies:
1. Request.getcookies returns an array
2. Store Chinese Cookie cookie = new Cookie ("name", Urlencode.encode ("Chinese"));
Urldecoder.decode ("value");

Session principle:
1, each Session object has a unique number, SessionID
2. The server is stored in the session by means of a cookie
3, when the browser is closed, because the session is saved in the server, when the browser is closed, the SessionID will not pass
4, Session.setmaxinactiveinterval (time);--Daze time, reach the maximum time
The default time is half an hour (1800s) in the Web configuration
Session.invalidate ();--destroy session immediately (equivalent to no session created)
Web Configuration:<servlet-config>
<time-out>1</time-out> minute Units
</servlet-config>
5. In Web. xml
<session-config>
<session-timeout>5</session-timeout> minutes
</session-config>
6, browser Close does not mean that the session object is deleted, saved in the server (Eclipsse server)
7. Session Persistence Management: Objects stored in it are stored in a serialized form (saved in a file)
8. Response: String URL = response.encodeurl ("address");--Distribution
9, should try to use a short maintenance time domain objects

JS Exam
1. JavaScript is a language that can only be run in a browser
2, "=": assignment "= =": value "= = =": full equality (data type, value)
3, Alert, setTimeOut belong to the window function
4. String = character array
5, length is the property, size () is the method
6, Test:boolean (True,false) Excute (): Returns the matching value
7. JS class selector for attributes: This.classname = "Same as selector name"
8. Element node: createelement () text node: createTextNode () Note node: createcomment () attribute node: CreateAttribute ()
9. The browser's support for traditional event assignment is better than modern events, and modern events are compatible
10, CSS priority: inline > Inline > External style! Importtant>id>class>element> pseudo-Class >*
11. js Event: Mouse event, keyboard event, HTML event
12. Refresh page: Trigger Load event and unload event
13, window.location.href= "";
14. Binding Event: Onclick= "click ()";///but.onclick=click;
15, submit Form document.forms[0].submit ();
16, h1*{color:red}--as long as the elements below the H1 are red
17, Display:none Visibility:hidden
18, Var temp = Null;alert (timeof temp);--object

Scope object: In a servlet you can bind an object with a name Setattritute ("name", name);
ServletContext (Application context)--The entire Web application (string,object);
HttpSession (session)--interface--a session interaction process
ServletRequest (Request)--a request process
Each servlet has its own servletcontext ();
Get Global variables
ServletContext sc = This.getservletcontext ();
ServletContext sc = this.getservletconfig (), Getservletcontext ();
ServletContext sc = request.getsession (). Getservletcontext ();
Sc.setattribute ("text", "MyText");--Declare global variables
Thread not secure

Session Scope session: For multiple requests from the same customer, the session is persisted across these requests
HttpSession session = Request.getsession ();
Session.setattribute ("name", "MySession");
Httpsessionlistener, Httpsessionactivationlistener: required to be registered in Web. xml

Servletcontext/httpsession/httpservletrequest
There are the same three ways: Setattribute,getattribute,removeattribute
Thread not secure

Request scope: cannot be accessed outside the scope of the request scope
Request.setattribute ("name", "name");
Thread Safety: Works between one request (available for distribution)

Listener: Session/request/application
Time the servlet was created: The first time a server was requested
Web. XML <load-on-starup>-11</load-on-starup> the smaller the more the servlet is created first
Change events for Web applications: Add, Delete, modify
Monitoring container: 1. Create Class 2. Implement Interface 3. Register Listener Web. xml
<listener>
<listener-class> Path to map </listener-class>
</listener>
Creation of global variables: When the server is started
Destroy: When the server shuts down
Setting global variables: Web. xml
<context-param>
<param-name>name</param-name>
<param-value>root</param-value>
</context-param>
Get Global variables:
ServletContext sc = Event.getservletcontext ();
String name = Sc.getinitparameter ("name");
Sc.setattribute ("MyName", name);

Request Text field: When a request is created

Packaging files? Compress files:

Servlet Filter: Intermediate component for intercepting messages between source data and destination data
(Filter the data passed between the two)
--You can change the content of the request, or reset the request header, and then deliver the request to the target resource, as well as the response
Multiple filters make up the filter chain;
Application:
Authentication filter;
Login and audit filtering;
image conversion filtering;
data compression filtering;
encryption filtering;
token filtering;
Resource access triggers event filtering;
XSLT filtering;
Mime-type filtering; in the Web server

All filters must implement the Javax.servletfilter interface Javax:java expansion pack
Filters need to be deployed in Web. xml
<error-page>
<error-code>404</error-code>//Error type
<location>error.html</location>//Jump to error page
</error-page>
<filter>
<filter-name>class name </filter-name>
<filter-class>class Package Name </filter-class>
Setting parameters
<init-param>
<param-name>code</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name> name of the map filter</filter-name>
<url-pattern>/need to filter the servlet</url-pattren>
<dispatcher>REQUEST</dispatcher>//default refers to request filtering
<dispatcher>FORWARD</dispatcher>//need to filter filters once
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>//Filtering for errors
</filter-mapping>
<!--as *, all to filter, even HTML
<url-pattern>/*</url-pattern>
Container creation: Filter open;
Container closed or overloaded: filter closed;

Filtercofig: Get Initialization parameters
Multiple filter: Advanced back-out
The position of the filter-mapping is in front, then filter is in front, first executes and then returns

Http://localhost:8080/Session/one.html
URI: Uniform identifier (later part)
URL: Version number, port number (all)
URI is part of the URL

Filter Packaging class: Httpservletrequest/httpservletresponse

XML: Extensible Markup Language
Jsp:java Server Page (JAVA server Pages)

Cookie session URL rewrite and exam

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.