Eleven, JSP and syntax summary

zhaozj2021-02-16  196

11.1 Overview JavaServer Pages (JSP) allows us to separate the static HTML and dynamic parts of the page. HTML can be written in any commonly used web making tool, and the writing method is also the same as the original; the code of the dynamic part is placed in a special tag, most of the "<%" starts with "%>". For example, the following is a piece of JSP page, if we use http: //host/orderconfirmation.jsp? Title = core web programming this URL opens this page, the result shows "THANKS for Order Web Programming". Thanks for Ordering <% = Request.getParameter ("Title")%> JSP page file usually with .jsp is extension, and can be installed to any place where a normal web page can be installed. Although the JSP page is more like a normal web page, the JSP page is more like a servlet, but in fact, JSP will eventually be converted into a regular servlet, and the static HTML directly outputs the output stream associated with the Servlet Service method. The conversion process of JSP to Servlet generally is performed when the first page request appears. So if you want the first user to wait too long because the JSP page is converted to servlet, I hope that the servlet has been properly compiled and loaded, and you can request this page after installing the JSP page. Also note that many web servers allow define alias, so a URL that looks to the HTML file is actually pointing to the servlet or JSP page. In addition to ordinary HTML code, other components embedded in JSP pages mainly have the following three: scripting element, command (Directive), Action. The script elements are used to embed Java code, which will become part of the SERVLET that is converted; the JSP instruction is used to control the structure of the servlet as a whole; the action is used to introduce an existing component or control the JSP engine. To simplify scripting elements, JSP defines a set of variables (predefined variables) that can be used (predefined variables), such as REQUEST in the front code segment is one of them. Note This article is based on JSP 1.0 specification. Compared with the 0.92 version, the new version of JSP made a lot of major changes. Although these modifications will only make JSP better, it should be noted that the JSP page of 1.0 is almost not compatible with the early JSP engines. 11.2 JSP Syntax Summary Table JSP Element Syntax Description Remarks JSP Expression <% = Expression%> Calculate the expression and output the result. Equivalent XML expression is: Expression Predefined variables can be used include: Request, Response, Out, Session, Application, Config, PageContext. These predefined variables can also be used in the JSP scriptlet. JSP Scriptlet <% Code%> Insert the code of the service method.

Equivalent XML expression is: Code JSP declaration <%! Code%> code is inserted into the servlet class (outside the service method). Equivalent XML expression is: Code Page Instruction <% @ Page Att = "VAL"%> Global Directive for the Servlet Engine. Equivalent XML expression is . The legitimate properties are as follows, with bold representation defaults: import = "package.class" contentty = "mime-type" isthreadsafe = "true | false" session = "true | false" buffer = "size kb | none" autoflush = "True | false" extends = "package.class" info = "message" errorpage = "url" iesrrorpage = "true | false" language = "java" include instruction <% @ include file = "URL"%> When JSP When converting into a servlet, a specified file on the local system should be included. Equivalent XML expression is: . Where the URL must be relative URL. Using JSP: Include Actions You can introduce files when requested (instead of JSP to servlet). JSP Note <% - Comment -%> Note; JSP is neglected when JSP is converted into servlet. If you want to embed the result html document, use a normal HTML annotation tag <- comment ->. JSP: Include action When the servlet is requested, the specified file is introduced. If you want to include a file while the page is converted, use the JSP Include instruction. Note: On some servers, the included file must be an HTML file or JSP file, which is determined by the server (usually determined according to the file extension). JSP: UseBean action or ... find or instantiate a Java Bean.

转载请注明原文地址:https://www.9cbs.com/read-8976.html

New Post(0)