1.Servlet Two defects: ① all HTML tags must be wrapped in a Java string, making it cumbersome to send HTTP responses, and ② all text and HTML tags must be hardcoded, even if the presentation layer is slightly modified, it needs to be recompiled.
2. Note: (1) JSP Note: <%%>, will not be sent to the browser, not nested (2) HTML notes:<!----, not handled by the container, sent directly to the browser, one of the purposes is to identify the JSP page.when working with applications with many JSP fragments, developers can easily find out what part of the HTML code generated the JSP page by looking at the HTML source code .。
3. Implicit objects:
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 |
Out is similar to the httpservletresponse called in the Page object that represents the current JSP page getwriter () after the resulting java.io.PrintWriter
4. Three syntactic elements: (1) Instruction directive: Indicates how the JSP converter should convert a JSP page to servlet ①page: The JSP Converter is instructed on some aspects of the current JSP page. The page directive can appear anywhere on the pages. Just when it contains the ContentType or pageencoding attribute, it must be placed before all the 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 contents of another file in the current JSP page. File extension .jspf (2) SCRIPT element scripting: Java code and Bi Gaocheng a JSP page ①scriplet: A variable defined in a scriplet that is also visible to other scriplet behind it ② declaration: Variables and methods that can be used on JSP pages ③ expression: Today is <%= java.util.Calendar.getInstance (). GetTime ()%> The semicolon is not required after the expression Close script elements: with the development of expression language, it is recommended to use El to access server-side objects instead of writing Java code in JSP pages. Therefore, the originally opened script element, you can define a SCRIPTING-INVALID element in the <jsp-property-group> of the deployment descriptor and close it, for example:<jsp-property-group> <url-pattern>*.jsp</url-pattern> <scripting-invalid>true</ Scripting-invalid></jsp-property-group> (3) Action action: Compiled into Java code to perform an action ①usebean: Create a script variable related to a Java object that separates the presentation logic from the business logic ②setproperty and GetProperty: Save and get a property in a Java object ③include action: & nbsp the difference between include directives and include actions:The include directive is used when a page is converted, such as when a JSP container transforms a page into a generated servlet, and the include action is used when the request occurs. parameters can be passed through the include action, but the include directive is not available. the file name extension of the containing resource is not important when using the include directive, and the file name extension must be a JSP when using the Include action ④forward: Jumps the current page to another different resource the difference between ForWord and redirect:http://zhulin902.iteye.com/blog/939049Http://www.2cto.com/kf/201109/105650.html
5. Error handling: (1) Use a try statement to process Java code (2) to specify a page that is displayed when the application encounters an unhandled exception. Using the Iserrorpage property of the page directive, you can turn a JSP page into an error handling page 6. Overview: (1) The JSP page is also a servlet, but simple multi-: ① do not need to compile JSP pages; ②*.jsp as extension text files that can be written in any text editor. (2) JSP pages run in a JSP container, and the servlet container is usually a JSP container. Tomcat is a servlet/jsp container. (3) The first time a JSP page is requested, the container does two things: ① the JSP page conversion car a JSP page implementation class, A Java class that implements the Javax.servlet.jsp.JspPage or Javax.servlet.jsp.HttpjspPage interface. Jsppage is a javax.servlet.Servlet subinterface, so each JSP page is programmed with a servlet. ② conversion succeeds, the container compiles the servlet class, loads and instantiates Java bytecode, and performs the life-cycle operations it typically does with the servlet. (4) for subsequent requests to the same JSP page, the container will see if the JSP page has been modified since the last conversion. If it is modified, it is converted, compiled, executed, or, if not, executes the servlet that already exists in memory. Therefore, the first time a JSP page is dropped is longer than subsequent requests. Measures to solve this problem: ① Configure the application to invoke all JSP pages for conversion compilation when the application starts instead of the initial request. ② pre-compiles JSP pages and deploys them in a servlet manner. (5) JSP API 4 Packages: &NBSP;①JAVAX.SERVLET.Jsp ②javax.servlet.jsp.target ③javax.el &N Bsp ④javax.servlet.jsp.el (6) JSP pages contain syntactic elements and template data: ①<% and%> are syntactic elements, 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 do I see the source code after the JSP is translated into a servlet? in the workspace of Eclipse \workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\catalina\localhost\ (project name) \ org\apache\jsp here.