One, the difference between a GET request and a POST request:
The 1.get request is passed through the URL parameter, the POST request is passed the parameter through the request body
2.get requests are allowed to pass a maximum of 255 characters, there is a limit to the length, so the data is relatively large when we use the POST request, especially when uploading with a POST request!
3.get request we can see the request parameters in the browser, and the post request in the browser address bar is not see the request parameters!
4. In the form, we usually use the POST request, except in the form, the other place in the page is basically use GET request!
The servlet is one of the three major components of the web; The three components of the Web are: servlet, Filter, Listener
Three, the life cycle
The servlet is managed by the Tomcat server!
Servlet life cycle: Refers to the process by which a Servlet object is generated to be destroyed!
The servlet life cycle involves several methods:
1. Constructor method: It is only called once when the servlet is first accessed, and is called once to indicate that the servlet is singleton, but the servlet is multithreaded,
Non-thread-safe, that is, in the servlet we try not to manipulate global variables in the service Method!
2.init method: The Init method is only called once when the servlet is first accessed, and the Servlet object is initialized!
The 3.service:service method is invoked every time the servlet is accessed, and our business logic is written in this service method!
4.destroy method:: Destroy method will only be called once when our project is unloaded, that is, when the server shuts down, it will be called once when the server is closed!
Iv. Forwarding and redirection
Forwarding: When the browser sends a request to the server, the server does not process itself, but calls other Web resources for processing!
Redirect: When the browser sends a request to the server, the server returns a special response to the browser, which tells the browser to send a request to another address!
forwarding and redirection differences:
The number of requests that occur on the browser or server browser The browser address bar has changed Browser is aware of
Forwarding [request] occurs on the server side &NB Sp 1 No change &nb Sp No sense
Redirect [response] occurs on browser side &NB Sp 2 & nbsp changes &NBSP ; CAN sense it!
Five, coding problem analysis and request coding
Communication between the two parties in the time of communication, in fact, the content of the communication "information" in accordance with certain rules into a binary communication
And this certain rule is the character encoding: Ascii,gb2312,gbk,iso8859-1,utf-8;
When the request arrives, the other party needs to decode it!
Garbled Reason:
The encoding and decoding methods of the communication parties are inconsistent,
Workaround:
Unified communication both the encoding and decoding methods, both use UTF-8 encoding!
Coding classification:
Request encoding
Browser Encoding---"Server decoding iso8859-1
Response encoding
Server encoding----"Browser decoding
The server side uses ISO8859-1 encoding by default, and the browser uses gb2312 by default, and of course we can tell the browser what encoding to use on the page!
GET Request:
The encoding format for the unified browser and server side is UTF-8 encoding: Specify the encoding format for UTF-8 encoding in the connector tag of the Server.xml file: uriencoding= "UTF8"
POST request!
We can set the decoding format in the Post method by Request.setcharacterencoding ("Utf-8") before obtaining the request parameter for the first time!
Java Basics-servlet Summary