JSP
-
Concept:
Java Server Pages: A Java Server page can be understood as a special page where you can specify and define HTML tags and Java code to simplify writingCopy the code
-
The principle of
A JSP is essentially a ServletCopy the code
-
JSP scripts: How a JSP defines Java code
1. <% code %>: Java code defined in the Service method. This script defines what can be defined in the service method. <%= code %>: Defined Java code, in JSP converted Java class member position 3. <%= code %>: defined Java code, will be output to the page. What can be defined in the output statement that can be defined in the scriptCopy the code
-
A built-in object for JSP
2. There are nine built-in objects in JSP. Request Response out: a character output stream object. You can output data to a page. Response.getwrite (), response.getwrite (), out.write() Before the Tomcat server actually responds to the client, it looks for the response buffer data, and before looking for the Out buffer data, the response.getwrite () data output is always before out.write()Copy the code
-
instruction
Function: used to configure JSP page, import resource file 2. Format: <%@ directive name Attribute name 1= Attribute value 1 Attribute name 2= Attribute value 2... SetContentType: response.setContentType() 1. Set the mime type and character set of the response body. 2. Set the encoding of the current JSP page. IsErrorPage: Indicates whether the current page is an error page. True: Yes, the built-in exception object can be used. False: No, the default value cannot be used. Page contains. 3. Taglib: Import resourcesCopy the code
-
Built-in objects
Objects that do not need to be created in a JSP page and used directly
A total of nine variables Name True Type Function pageContext pageContext The current page shares data, as well as eight other built-in objects. Request HttpServletRequest Requests access to multiple resources at one time HttpSession Data is shared between multiple requests in one session. Application ServletContext Data is shared between all users. Response HttpResponse Response Object Page Object Object of the current Object (Servlet) Config ServletConfig Servlet Configuration object Exception Throwable exception object this out JspWrite output objectCopy the code
-
Express Language (EL) expression
-
operation
+ - * /(div) %(mode) 2. Comparison operators: > < >= <= =! = 3. The logical operators: && (and) | | (or)! Empty function: used to determine whether a string, set, or array object is null and whether the length is 0Copy the code
-
Get the value
1. The el expression can only get a value from a domain object. 2. Key name}: gets the value of the specified key from the specified field. 1. pageScope -----> pageContext 2. requestScore -----> request 3. sessionScope ----> session 4. applicationScope -----> ${requestScope. Name} = ${requestScope. Name} = ${requestScope. Name} = ${requestScope. Get the value of the object,List,Map collection 1. Property name} essentially calls the getter method of the object. List collection: ${domain name. Key [index]} 3. Map set ${domain name. Key name} ${Domain name. Key name [" key name "]} 4. Implicit objects in the el expression in 11 pageContext implicit objects: access to the JSP eight other built-in objects ${pageContext. Request. ContextPath} : dynamic virtual directoryCopy the code
-
JSTL
JavaServer Pages Tag Library is an open-source, free JSP Tag Library provided by the Apache organization. Purpose: To simplify and replace Java code on JSP pages 3. Use Step 1. <% @taglib %> 3. Use a labelCopy the code