Basic syntax
JSP only embeds some dynamic elements on the basis of HTML. Here is the HelloWorld code:
The <%%> in the above code is the dynamic element. All the special syntaxes in the JSP are as follows:
<%%>: Used to represent a piece of Java code. This code is placed in the _jspservice () method after compilation.
<%! %>: An exclamation mark is also used to represent a piece of Java code, but this code is compiled and placed in a JSP-generated servlet class, so you can use it to define a method or a member variable.
<%@%>: More than one @ symbol, is the JSP directive, used to set up the JSP file.
<%=%>: An equal sign, equivalent to OUT.PRINTLN ().
<%----%>: This is a comment. Does not appear in the returned results.
JSP directives. There are three types of instructions that can be set:
<%@ page%><%@ include%><%@ taglib%>
The properties that the page directive can set are as follows:
- Buffer sets the size of the Out object buffer.
- AutoFlush controls the buffer of the Out object.
- CONTENTTYPE Specifies the MIME type and character encoding of the current JSP page
- ErrorPage Specifies the page to turn when a JSP page exception occurs
- ISERRORPAGE Specifies whether the current JSP page can be used as an error page for another page. The error page can be used to get error information directly using the exception implied variable.
- extends specifies which class the servlet inherits from
- Import imports the package to use
- Info defines the description information for the JSP page
- ISTHREADSAFE Specifies whether the JSP page is thread safe
- language Specifies the programming language, which defaults to Java
- session Specifies whether the JSP page uses the session
- iselignored Specifies whether to specify an El expression.
- isscriptingenabled Specifies whether the script element can be used. If False, an error occurs in the JSP if <%%> appears.
The include directive is used to include a file. The syntax is <%@ include file= "xxx"%>. Works at compile time.
The taglib directive is used to load a custom tag library. Syntax for <%@ taglib uri= "uri" prefix= "xx"%>
Action elements
- <jsp:scriptlet> and <%%> are equivalent.
- <jsp:expression> and <%=%> are equivalent.
- <jsp:include> contains files that work in the process of execution.
- <jsp:useBean> Initializing a JavaBean component
- <jsp:setProperty> Setting properties for JavaBean
- <jsp:getProperty>
- <jsp:forward> passing requests to another JSP file.
- <jsp:plugin> contains applets and JavaBean objects in the generated page. It is replaced with the embed or the object tag during execution.
- <jsp:element> Create XML elements dynamically.
- <jsp:attribute> defining dynamically created XML element properties
- <jsp:body> dynamically creates the body of an XML element.
- <jsp:text> with CDATA, displays the content in CDATA, but does not perform label actions in CDATA. such as the following code:
<jsp:text><! [cdata[
The result of the final output is:
The <jsp:world/> inside was not executed.
All the action elements are executed during the execution of the Servlet code. It is therefore important to note the Jsp:include action, which is the introduction of a file in the process of Servlet execution. This is different from the <%@ include file= ""%>, which was introduced at compile time.
All action elements contain the ID and scope properties. The ID is used to get an action element through PageContext, which defines the life of the object.
The usage of Usebean, SetProperty and GetProperty. The role of Usebean is to introduce a javabean that needs to provide ID and class two parameters. The ID is the name of the variable, and class is the type of the variable. SetProperty can be placed inside the usebean tag, which means that it is called when initialized. If you follow the existing JavaBean, the statements inside the tag are not called.
<jsp:usebean id= "test" class= "test. Testbean "> <jsp:setproperty name=" test "property=" name "value=" value "/></jsp>
The code for dynamically creating elements is as follows:
<jsp:element name= "Employee" > <jsp:attribute name= "name" > Zhang San </jsp:attribute> <jsp: Body> Zhang San is the sales department manager </jsp:body></jsp:element>
The code will produce:
<employee name= "Zhang San" > Zhang San is Sales manager </employee>
White Coffee
Blog Address: Http://blog.csdn.net/caipeichao2