Common instruction learning and JSP development instruction in jsp development
(1) JSP commands
JSP Commands include page commands, include commands, and taglib commands.
(2) role of the page command
Syntax:
<% @ Page property name 1 = "property value 1"... property name n = "property value n" %>
1. import: import a Java class or package on the specified JSP page.
2. session: Restrict whether the session is available. The default value true indicates that the session is available, and fasle is unavailable.
3. isErrorPage: Specifies whether the JSP page is used to handle abnormal error pages. If it is set to true, exception is available. The default value is false.
4. errorPage = "URL": when a page exception occurs, it is the jump path.
5. contentType = "text/html; charset = UTF-8": the browser determines the document type based on the appearance.
6. pageEncoding: Specify the page encoding format.
7. autoFlush = "true | false": indicates whether the buffer is automatically cleared. The default value is true.
8. info = "text": describes information about the JSP page.
9. isThreadSafe = "false | true": whether to allow multithreading to use this page. The default value is true.
10. buffer = "8 KB": indicates whether the output stream has a cache. The default value is 8 KB.
11. Extends = "class": Specifies the parent class inherited by the Servlet generated on the JSP page.
(3) include commands to introduce files
<% @ Include file = "file path (either absolute or relative)" %>
Instance demo
<% @ Page import = "java. util. date "%> <% @ page language =" java "contentType =" text/html; charset = UTF-8 "pageEncoding =" UTF-8 "%> <! -- Embed HTML in JSP --> <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "https://www.w3.org/TR/html4/loose.dtd">
Output:
(3) taglib commands related to tags
Import package: jstl-1.2.jar, jstl-standard.jar
<% Taglib uri = "tagliburi" prefix = "tagPre" %> uri: indicates the location where the custom tag library is stored. prefix: distinguishes the tag names of different tag libraries.
Example:
<% @ Page language = "java" contentType = "text/html; charset = UTF-8 "pageEncoding =" UTF-8 "%> <% @ taglib uri =" https://java.sun.com/jstl/core_rt "prefix =" c "%> <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "https://www.w3.org/TR/html4/loose.dtd">
In the browser address bar, output: https: // localhost/Project/index. jsp? Username = "Kaina ":
Output: