Introduction to JSP, servlet-related knowledge (GO)

Source: Internet
Author: User
Tags html header http post

1. servlet Life cycle

The so-called life cycle refers to the entire process of how a servlet container creates a servlet instance, allocates its resources, invokes its methods, and destroys its instance.

Phase one: instantiate (that is, create a Servlet object, call the constructor)

Object instantiation occurs in the following two scenarios.

First case:

When the request arrives at the container, the container finds whether the Servlet object exists and if it does not, the instance is created.

Second case:

When the container is started, or when an application is newly deployed, it checks whether the servlet has a Load-on-starup configuration in Web. Xml. If so, the servlet instance is created.

The lower the Load-on-starup parameter value, the higher the priority (the minimum value is 0, the highest priority).

Phase two: initialize

Assign a resource to the servlet, call init (servletconfig config);

The Config object can be used to access the servlet's initialization parameters.

Initialization parameters are parameters that are configured with Init-param.

Init can override.

Phase three: Ready/Call

There is a request to reach the container, and the container invokes the Servlet object's service () method.

The service () method of HttpServlet calls the Doget () or Dopost () method according to the requested method. However, these two do methods, by default, throw an exception and require subclasses to override.

Phase IV: destruction

The container removes the Servlet objects that are no longer needed, based on its own algorithm.

The Destroy () method of the Servlet object is called before it is deleted.

The Destroy () method is used to release resources.

Throughout the servlet's lifecycle, Init,destroy executes only once, and the service method executes multiple times.

2. The difference between JSP and servlet

1.The JSP has been compiled into a servlet. (The essence of JSP is that SERVLET,JVM can only recognize Java classes, not the code of the JSP, the Web container compiles the JSP code into the Java class that the JVM can recognize) 2.JSP is better at displaying the page, and the servlet is better at logic control .   3.There are no built-in objects in the servlet , and the built-in objects in the JSP must be obtained by HttpServletRequest objects, HttpServletResponse objects, and HttpServlet objects. JSP is a simplification of servlets, the use of JSP only need to complete the programmer needs to output to the client's content, JSP java script How to mosaic into a class, by the JSP container to complete. The servlet is a complete Java class, and the service method of this class is used to generate a response to the client.

3, the difference between get and post in HTTP

1. TheGet method passes the user's data through a URL request, connects the field names in the form with their contents, paired strings , and places the URL of the program that the Action property refers to, such as [url]http://www.mdm.com/ Test.asp?name=asd&password=sad[/url], the data is displayed directly on the URL, just as the user clicks on a link, and the Post method uses the HTTP post mechanism to place the names of the fields within the form with their contents The HTML header (header) is sent to the server side by the Action property can refer to the program processing, the program through the standard input (stdin) method, the form of data read out and processed , Post mode has a block for the parameters of the area.
2, get method need to use Request.QueryString to get the value of the variable, and Post way through Request.Form to access the content of the submission
3.The amount of data transferred by the Get method is very small and can only be transmitted text. The general limit is around 2 KB, but the execution efficiency is better than the Post method, and the post way to pass a relatively large amount of data , you can transfer large text and binary data, such as files, it is waiting for the server to read the data, but there is a byte limit, This is to avoid malicious attacks on the server with a large amount of data, according to Microsoft, Microsoft to use Request.Form () can receive the maximum data limit, IIS 4 is a KB byte, iis 5 in KB bytes
Recommendation: Unless you are sure that the data you submit can be submitted at once, please use the Post method as much as possible
4,get way to submit data, will bring security issues , such as a landing page, through the Get method to submit data, the user name and password will appear on the URL, if the page can be cached or other people can access the customer this machine, you can obtain the user's account and password from the history record , so the form submission recommends using the Post method; The common problem with the form page submitted by the Post method is that if the page is refreshed, a dialog box pops up
Recommendation: For security reasons, it is advisable to submit data using Post

4. The difference between HTML and JSP

HTML (hypertext Markup Language) Text Markup Language, it is a static page, and JavaScript as the explanatory language, why is it interpreted language? Because, as long as you have a browser then it can be displayed normally, without the need for the specified compilation tool, just write the HTML tag in the TXT document OK. JSP (Java Server page) to see this meaning is the Java service side of the page, so it is dynamic, it needs to be compiled after the JDK to send the content to the client to display, we all know that the Java file compiled will produce a class file, The final implementation is the class file, JSP is the same, it will be compiled into a class file! JSP not only to compile, it has to be translated, first the JSP translated into a servlet file, and then compiled into a class file. When the user accesses the JSP, it executes the class file and finally ...

2. The definition on the HTML page is a static page can be run directly, the JSP page is a dynamic page which needs to be converted into a servlet when it runs.  
4. It is also very good to distinguish between the use of <%%> in JSP can write Java code, and HTML does not have <%%>.

Http://www.cnblogs.com/0201zcr/p/4693365.html

Introduction to JSP, servlet-related knowledge (GO)

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.