Java EE Learning record 3

Source: Internet
Author: User
Tags set time

Servlet
    1. Java programs running on a Web server or application server
    2. Create dynamic content (effective and powerful) solutions on the Web
    3. The container to manage the lifecycle "load (create) program, initialize, service, terminate (destroy), uninstall" and interact with the server
    4. Features by Sun specification
Servlet life cycle
    1. Load: Specifies the location (package and class name) of the servlet through the Web. XML configuration, and after success, it is instantiated by the reflection servlet.
    2. Initialize: Invokes the Init () method to initialize the instantiated object. Do some initialization work (establish database link, read source file information, etc.) before processing the request. Initial failure, directly uninstalling the servlet.
    3. Service: invokes the Service () method to process the request. ServletRequest processes the request, Servletresponse sets the response information.
    4. Destroy: The Web container automatically calls the Destroy () method when the servlet is removed from the container.
    5. Uninstall: After the servlet calls the Destroy () method, this instance is reclaimed by the garbage collector and needs to be reused again to initialize Init ().

It is normally initialized, destroyed only once, and is called multiple times under special circumstances, such as if the servlet is not in use for a long time.

Servlet Basic Configuration
    1. Exact match:
      <url-pattern>/servlet/MyServlet.do</url-pattern> '
    2. Directory Matching:
      <url-pattern>/servlet/*</url-pattern>
    3. Name extension matches:
      <url-pattern>*.do</url-pattern>

Container lookup: exact match > directory match (starting from longest directory match) > extension match

ServletContext: Application Context
只有一个,所有对象都可以访问它。(全局的)
ServletConfig
只有一个Servlet对应。作用域比ServletContext小。
Convert virtual path to physical path
getResourcePaths(java.lang.String path):getResourceAsStream(java.lang.String path):getResource(java.lang.String path)

Status line: HTTP protocol, status code, status description

How the browser sends requests to the server
    1. Browser Input URL Address
    2. Click the hyperlink
    3. Form submission
How the browser sends requests to the server
    1. Browser input URL address (GET method)
    2. Click the hyperlink (Get method)
    3. Form submission (Get, POST method)
Get, post method differences:
get post
Data type Text Text, binary text
Data length No more than 255 characters No Limits
Visibility of data Displayed as part of the URL address in the browser address bar As the requested message body, not visible
Data caching Cached in the browser URL history state Will not be cached by the browser
HTTP request Settings Request redirection:
    1. You can select a different server-side program to process the request
    2. Redirect the request to a completely different URL
Request forwarding and request REDIRECT differences:
    1. Redirect is the client browser to complete, request forwarding is the server side to complete
    2. The URL address of the redirected browser will change, and request forwarding will not
    3. Redirect the client browser to make two requests and responses, and request forward only one request and response

To set up automatic refresh and wait pages: Response.setheader ("Refresh", "time; Url=url "); "Refresh" has a browser compatibility issue.

Web state Management state Management solution:
    1. Hidden Fields (Cons: Must be dynamic pages to be valid)
    2. Cookie (disadvantage: The data is saved on the client, the user can disable the cookie, and the cookie can be erased, visible, unsafe. )
    3. session (sessions, stored on server): Extinction->1. Timeout (can be set time) 2. Manual shutdown 3. System crashes when the Web server shuts down

Java EE Learning record 3

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.