Java EE Attack (iii)--jsp

Source: Internet
Author: User

The previous blog mentions servlet technology, and this article is about a servlet extension application--jsp.


Background generated by the foundation

When you output a page to a client browser in a servlet, we use quite a few

PrintWriter out = Resp.getwriter ();
Out.println ("

Out.println ("...");

。。。

Such a statement, this operation is extremely cumbersome, often we would like to operate the HTML language, the server side to achieve WYSIWYG effect, in the end there is a technology so that we can directly write HTML tag text to the browser to complete the effect of sending the page? That's JSP.


Conceptual analysis

Jsp:java server Pages, the basic implementation is a servlet, that is, JSP is also running on the server side of a program.

When the browser accesses the JSP file for the first time, the servlet container automatically compiles the JSP file code into a servlet program (which can also be compiled in advance by the precompiled tool) and is further executed, in subsequent accesses, if the JSP file is not changed. The JSP file is not compiled, which is why it is slow to access the JSP resource for the first time.



Invoke process

1. Client requests to server side;

2. Server-side processing requests

--Generate Request Object HttpServletRequest (contains client information)

--Generate the corresponding object HttpServletResponse (contains server response information)

--Call the service method of Jspservlet, will perform the operation of compiling the corresponding JSP file, generate the corresponding Java, class file, including the corresponding JSP file Java class, inherit from Httpjspbase.

--instantiation of the corresponding JSP class

--Call the service method of its parent class

--Call the override method _jspservice (the method contains the compiled program for the JSP page that was written)

3. Generate the response page and pass it to the servlet container.

4.Servlet Returns the response to the client

5.Srvlet Container calls Destory method destroys instantiated objects

Flow chart:


Similar to servlet, we can also find the relevant configuration information for JSP requests.

This configuration information is available under the Tomcat file \conf\web.xml

The beginning has been mentioned, JSP is actually servlet, and from the configuration file, according to the Url-pattern property, we can know that JSP is nothing but as a file suffix name is tomcat capture execution, so in fact, changed the file extension, do the configuration file, You can also implement the JSP to achieve the same effect.

It should be emphasized here that when the client requests the JSP page for the first time, the servlet container compiles the corresponding JSP page, generates the relevant Java, class file, which can be found in the Tomcat folder: \work\catalina\localhost\ test_jsp\org\apache\jsp, open the Java file to see the relevant methods, so we understand that Tomcat is actually helping us to translate the JSP page into what kind of a class.


Features JSP and JS

JSP page writing is very similar to HTML pages, which can be carried Java script code, formally, this is like the HTML page to write some JS code, the fundamental difference is that JSP is running on the server side of a technology, is designed for Servlets to send HTML pages to the browser, allowing developers to write servlets like HTML pages.

The first generation of JS is to enable the client to form validation, but later development, its function becomes more and more powerful, has become an indispensable basic technology in the previous paragraph.


JSP and ASP

1.jsp Cross-platform--java the operating mechanism of the decision

2.web server Support-that's not too deep, just take it here

3. Component model--jsp involves some of the javabean, while ASP uses a Win32-based COM component model

4. Scripting language--jsp can be written in Java or JS, while ASP pages use VBScript or JScript


Summarize


This article on the JSP response technology has been introduced, in fact, in understanding the servlet technology under the premise of JSP is not so difficult, for some of the details of the JSP, such as built-in objects, tags and other content with the gradual application in the later believe will also be the corresponding understanding and learning



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.