Second, the use of JSP to achieve output
JSP page composition: Static content, instructions, expressions, scriptlet, declarations, actions, annotations
JSP scripts: Expressions, scriptlet, declarations
Expression: <%= content%>
Scriptlet: <% Java code%>
Disclaimer: <%! Java variables, methods%>
JSP directives: page, include, taglib
2.1 Use page to specify Settings page properties
- Set the character set pageencoding
- Set Language language
- Importing package Import
- Specify buffer size (Kbytes) buffer
- Specifies the URL of the error handling page ErrorPage
- Whether the page is an error handling page Iserrorpage
- 7. whether to ignore the calculation of the EL expression iselignored
The character set of the newly created JSP page is iso-8859-1, and the Chinese character cannot be saved at this time.
<%@ page language="java" contenttype="text/html; Charset=iso-8859-1 "
pageencoding="Iso-8859-1"%>
Saving kanji requires the use of utf-8 characters. You can reset the new file to be utf-8.
2.2 Include directives
The runtime embeds an HTML file or JSP page into another JSP page.
<%@ include file= "file name"%> executes fast and executes directly with the original file
<jsp:include page= "File" flush= "Ture" > Encounters this line in edit, returning the result.
2.3 taglib directive
Introduce the Tag library profile (TLD) into the page and set the prefix to use the label's tag in the tag library description file. The tag descriptor file is in XML format and contains a series of label descriptions whose file suffix is. tld.
<%@ taglib url= "tag Library descriptor file" prefix= "prefix name" >
2.4 Out for page output
<% out.println ("My JSP page"); %>
<% Out.print ("My second webpage"); %>
Output effect:
To view the source file:
2.5 notes
The comments in the JSP are divided into three types:
- 1. HTML annotations
<!--HTML comments--
- 2. JSP annotations
<%--JSP comments--
- 3. JSP Script Comments
<%
/* Multiline Comment */
Single-line Comment
%>
The difference between the three is: HTML comment is not secure
Instance:
Effect:
Source:
2.6 JSP declaration and use variables
1. <%%> Local Variables
2. <%! %> all variables and methods
3. Escape characters:
1) Single quote ' changed to '
2) Double quotation mark "instead of"
3) slash \ Change to \ \
4) Start tag <% change to <%
5) end tag%> change to%\> or%>
2.7 JPS expression for page output
<% Out.print (); %>
<%=%>
Note: When you need to import additional packages in an expression, use the page directive, where multiple packages are written together, separated by commas (,).
2.8 JSP Execution principle
The generated Java files and class files are saved in the project path in work
1) Client Request
2) The Web container translates the JSP page into the source code of the servlet. Java
3) The source code generated by the Web container is compiled . Class
4) The Web container loads the compiled code and executes
5) respond to the results of the execution to the client
2.9 Common Web Program errors
1) 404 cannot find a page or resource to access
Possible causes: URL input error at run time
Place the page under Web-inf
External boot tomcat, project not deployed
2) JSP page code error
Possible error: JSP page code has errors
jsp-02-using JSP for output