2.2.1 Tell me the difference between HTTP GET and POST requests
Both the Get and post requests are HTTP requests, and the user accomplishes different actions on the resource (URL) through different HTTP requests, specifically, get is used to get/query resource information, and post is used to update resource information.
HTTP defines the different methods of interacting with the server, the most basic method is the Get,post,put,delete,url full name is the resource descriptor, we can think of this: a URL address, which is used to describe a network of resources, and HTTP Get,post , Put,delete is corresponding to the resources of the search, change, increase, delete 4 operations, specific points get is generally used to get/query resource information, and post is generally used to update resource information.
1) The data submitted by the GET request is displayed in the Address bar, and the POST request is not displayed in the Address bar.
The data for the Get submit request is appended to the URL (that is, the data is placed in the HTTP protocol header). Split the URL and transfer data, multiple parameters with & connection; Post submission: The submitted data is placed in the package body of the HTTP packet, so the data submitted by get is displayed in the Address bar, and the address bar does not change when the post is submitted.
2) The size of the transmitted data
HTTP GET requests are limited by the amount of data that is transferred due to browser restrictions on address length, and post requests do not restrict transmission of data due to address length limitations.
3) security, post security is higher than get security, because the data will be presented in the address, so security can be history to find password-related information.
2.2.2 Tell me about your understanding of the servlet? Or what is a servlet?
The Servlet applet, the full name of the Java servlet, is a server-side program written in Java that implements the Servlet interface, whose main function is to interactively browse and modify data, generate dynamic Web content, The servlet runs in a Java-enabled application server.
HttpServlet overrides the Doget and Dopost methods, or you can override the service method to complete the response to the Get and post requests.
2.2.3 A brief talk about the life cycle of the servlet?
Servlets have a good lifetime definition, including loading and instantiation, initialization, processing requests, and end of service, which is expressed by the Init,service,destory method of the Java servlet servlet interface.
When the servlet starts, starts loading the servlet life cycle, the servlet is instantiated by the server, the container runs its Init method, the request arrives, runs its service method, and the service method automatically dispatches the Doxxx method to run and request it (Doget, DoPost) and so on, when the server decides to instantiate the destruction (server shutdown) call its Destory method
The init of the class--> instantiation servlet that loads the servlet finishes initializing the response request (Servlet's service method) when the-->servlet container is closed (Servlet's Destory method)
What is the difference between forward () and redirect () in the 2.2.4 Servlet API?
The former is only the steering of control in the container, in the client browser address bar will not show the post-turn address, the latter is a full link, the browser (client) will get a link to jump, and resend the request link. Forward is still the original request and Rediect is a re-launch request. In this way, from the browser's address bar can be seen after the jump link address, so the former more efficient, in the former can meet the need, as far as possible to use the forward () method, and this helps to hide the actual link, in some cases, for example, To jump to a resource on a different server, you must use the Sendredirect () method.
1) forward is the redirect of the server request and Rediect is the client's jump.
2) The address of the forward browser will not change, and the redrect will change.
3) forward is completed in a single request, and Redrect is a re-originating request.
3) Forward is done on the server side without the client re-initiating the request, which is highly efficient.
What are the similarities and differences between 2.2.5 JSP and servlet, and what are the links between them?
The JSP is an extension of the servlet. All JSP files are translated into a class that inherits HttpServlet, which means that the JSP is eventually a servlet, and the servlet provides services to the outside.
The main difference between Servlets and JSPs is that if the servlet is going to implement HTML, it must be cumbersome to use writer's output of the corresponding HTML, the application logic of the servlet is in the Java file, and is completely separated from the HTML in the presentation layer. The JSP case is that Java and HTML can be combined into an extension of. jsp file is more convenient and embedded logic is more complex, JSP side attention to the diagram, servlet is mainly used for control logic.
What are the built-in objects for 2.2.6 JSP? What are the roles?
9 Built-in objects:
Request user requests, this request will contain parameters from the Get/post request
Response Web page back to the client's response
The properties of the PageContext Web page are managed here
Session Chess related to request
What the application servlet is doing
Output used to transmit a response
Config Servlet's architectural parts
Page JSP webpage itself
Exception for error pages, no catch exceptions
Four scopes: Pagecontext,request,session,application can take values from four scopes through JSTL
JSP Pass value Request,session,application,cookie can also pass value
2.2.7, what's the difference between a session and a cookie? Where do you use the project?
Sessions and cookies are session tracking technologies, where cookies determine the user's identity through client-side record information, and the session determines the user identity on the server, but the session implementation relies on Cookie,sessionid ( The session's unique identity needs to be stored on the client)
The difference between Cokike and session
1) The cookie data is stored on the client's browser and the session data is stored on the server.
2) Cookies are not very secure, others can analyze local cookies and cookie spoofing, taking into account that security should use the session
3) session will be stored on the server for a certain period of time, when the increase in access, will compare the performance of your server to reduce server performance, you should use cookies
4) A single cookie cannot hold more than 4k of data, and many browsers restrict a site to save up to 20cookie
5) so personal advice:
Store important information such as login as session, and other information, if necessary, can be stored in a cookie, such as a shopping cart.
The shopping cart is best to use cookies, but cookies can be disabled on the client side, and we will use the cookie+ database as a way to get the data from the database when it cannot be fetched from the cookie.
What are some of the techniques 2.2.8 MVC has to achieve
M (model) models Javabean,hibernate,mybatis
V (view) Code view jsp,html,freemaker,velocity
C (Controller) Controllers servlet,action,struts
Jsp+servlet+javabean The most classic MVC pattern. In fact, the way Model2 is implemented is to isolate views and logic.
The way of Model1 Jsp+service+dao
The way of Model2 Jsp+servlet+service+dao
With an MVC structure such as struts2 and SPRINGMVC, the jsp+ core controller +action+javabean
Java Interview ③web section