Servlet learning notes (7) -- JSP overview, servlet learning notes
1. servlet has two defects: ① All HTML tags must be included in Java strings, which makes sending HTTP responses very complicated; ② All text and HTML tags must be hardcoded, even if you make minor changes to the presentation layer, You need to recompile it.
2. Note: (1) JSP remarks: <%>, not sent to the browser, cannot be nested (2) HTML remarks: <! -->, Directly sent to the browser without being processed by the container. One purpose is to identify the JSP page. When processing applications with many JSP fragments, developers can view the HTML source code to easily find out which JSP page is generated in an HTML code part.
3. Implicit object:
Object |
Type |
Request |
Javax. servlet. http. HttpServletRequest |
Response |
Javax. servlet. http. HttpServletResponse |
Out |
Javax. servlet. jsp. JspWriter |
Session |
Javax. servlet. http. HttpSession |
Application |
Javax. servlet. ServletContext |
Config |
Javax. servlet. ServletConfig |
PageContext |
Javax. servlet. jsp. PageContext |
Page |
Javax. servlet. jsp. HttpjspPage |
Exception |
Java. lang. Throwable |
The out is similar to calling the page Object in HttpServletResponse to indicate the java. io. PrintWriter obtained after the current JSP page getWriter ().
4. three syntax elements: (1) directive direve ve: instructs the JSP converter how to convert a JSP page to Servlet ① page: instructs the JSP converter on some aspects of the current JSP page. The page command can appear anywhere on the page. Only when it contains the contentType or pageEncoding attribute, it must be placed before all template data and before any content is sent using Java code. This is because the content type and character encoding must be set before any content is sent. ② Include: place the content of another file on the current JSP page. File extension. jspf (2) script element scripting: converts Java code to a higher ratio into a JSP page ① Scriplet: variables defined in a Scriplet are also visible to other scriplets behind it ② declaration: variables and methods that can be used on the JSP page ③ expression: Today is <% = java. util. calendar. getInstance (). getTime () %> the Expression does not need to be followed by a semicolon to close the script element. As Expression Language develops, we recommend that you use EL to access objects on the server, rather than writing Java code on the JSP page. Therefore, you can define a scripting-invalid element in the deployment descriptor <jsp-property-group> to close the script element. For example: <jsp-property-group> <url-pattern> *. jsp </url-pattern> <scripting-invalid> true </scripting-invalid> </jsp-property-group> (3) action: java code compiled to execute an action ① useBean: Creates a script variable related to a Java object and separates the presentation logic from the business logic ② setProperty and getProperty: save and obtain an attribute in a java object ③ include action: the difference between include instruction and include action: include instruction is used during page conversion, for example, when the JSP Container converts a page into a generated Servlet; inclu The de action is used when a request occurs. Parameters can be passed through the include action, but the include command cannot. When the include command is used, the file extension of the contained resource is not important; when the include action is used, the file extension must be jsp ④ forward: the difference between forword and redirect that redirects the current page to another resource: http://zhulin902.iteye.com/blog/939049 http://www.2cto.com/kf/201109/105650.html
5. Error Handling: (1) Use the try statement to process Java code (2) specify a page so that it is displayed when the application encounters an uncaptured exception. By using the isErrorPage attribute of the page command, you can change a JSP page to an error handling page. 6. summary: (1) the Jsp page is also a Servlet, but it is much simpler: ① JSP page does not need to be compiled; ② *. jsp is a text file with the extension, which can be written in any text editor. (2) JSP pages run in JSP containers. Servlet containers are also JSP containers. Tomcat is a Servlet/JSP Container. (3) The first time a JSP page is requested, the container does two things: ① Converting the JSP page into a JSP page implementation class, that is, javax. servlet. jsp. jspPage or javax. servlet. jsp. java class of the HttpjspPage interface. JspPage is a sub-interface of javax. servlet. Servlet. Therefore, each Jsp page is programmed with a Servlet. ② After successful conversion, the container compiles the Servlet class, loads and instantiates the Java bytecode, and executes the lifecycle operations that are usually performed on the Servlet. (4) for subsequent requests from the same JSP page, the container will check whether the JSP page has been modified since the last conversion. If it is modified, it will be re-converted, compiled, and executed. If it is not, it will execute the existing Servlet in the memory. Therefore, the first time a JSP page is dropped is longer than the subsequent request. Solution: ① configure the application and call all JSP pages for conversion and compilation when the application is started instead of the initial request. ② Pre-compile JSP pages and deploy them as servlets. (5) Four jsp api packages: ① javax. servlet. jsp export javax.servlet.jsp.tar get ③ javax. el ④ javax. servlet. jsp. el (6) JSP pages contain syntactic elements and template data: ① <% and %> is a syntactic element, and HTML tags and text are template data. (7) JSP does not need to be labeled in the deployment descriptor or mapped to a URL
(8) after adding a new JSP page, you do not need to restart Tomcat 7. How to view the source code after JSP is translated into servlet? In the eclipse workspace \. metadata \. plugins \ org. eclipse. wst. server. core \ tmp0 \ work \ Catalina \ localhost \ (project name) \ org \ apache \ jsp here.
Will XP make full use of hardware than 98, so that the game runs smoothly?
As a system that has served for more than ten years, it has ushered in its own home. Now, netizens around the world can't help but respect this tenacious system that exists in microsoft for more than 10 years. Only by constantly exploring, trying, and innovating can we make the system operation more humane. This is not comparable to XP 7 and 8.1.
Which of the following statements about JSP and SERVLET are true? (Multiple options)
It should be: ABC