JSP Introduction: (Understanding)
1) JSP background
① in many dynamic Web pages, most of the content is fixed, only the local content needs to be dynamically generated and changed;
② If you use a servlet program to output a Web page that only local content needs to be dynamically changed, all of the static content needs to be generated by the programmer in Java program code, the entire Servlet program code will be very bloated, writing and maintenance will be very difficult;
③ the design of large amounts of static content and the writing of related HTML statements is not a programmer's job, and programmers are not necessarily good at it. Web design and production staff do not understand Java programming, is not able to complete such work;
④ to compensate for the servlet's shortcomings, Sun has launched the JSP (Java Server Pages) technology as a solution based on the servlet ;
⑤ JSP is a technique that simplifies the servlet writing, which mixes Java code and HTML statements in the same file, writes only the content that is generated in the Web page in Java code, and writes the static content in a normal static HTML page.
2) About JSP
The ①SP page is an ordinary text file consisting of an HTML statement and a nested Java code, and the JSP page must have a. jsp file name extension.
② Java code written in JSP pages needs to be nested in <% and%> , and Java code nested between <% and%> is called a script fragment (Scriptlets), not nested in The content between <% and%> is called the JSP template element;
Java code in ③jsp can use the OUT.PRINTLN statement to output the resulting string generated by other Java program code to the client, or you can use the SYSTEM.OUT.PRINTLN statement to print them to a command-line window;
④jsp files are like normal HTML files, they can be placed in a Web application in any directory except Web-inf and its subdirectories, and the access path of the JSP page is exactly the same as that of the normal HTML page ;
⑤ can also use an element called a jsp expression in a JSP page, and simply encapsulate the variables or expressions that will be exported directly into the <%= and%> , and you can output the result of the operation of this variable or expression to the client. A variable or expression nested within a JSP expression cannot have a semicolon after it.
3) How the JSP works (JSP is essentially a servlet)
When the ①web container (servlet engine) receives a request for access to a URL with an extension of. JSP, it will give the access request to the JSP engine for processing;
② Each JSP page is accessed for the first time, the JSP engine translates it into a servlet source program,
The servlet source program is then compiled into a servlet class file, which is then loaded and interpreted by the Web container (servlet engine) in the same way as a normal servlet program to execute the servlet program translated by the JSP page;
The ③JSP specification does not explicitly require that the script code in the JSP be in the Java language, and that the script code in the JSP can be written in a scripting language other than the Java language, but that the JSP page must eventually be converted to a Java servlet program;
④ can pre-compile all of its JSP pages into a servlet program before the Web application is officially released
[Original]java Web Learning Note 13:jsp Introduction (background, features, principles)