JSP syntax is taken from: http://www.cnjsp.org/view.jsp? Column = 2 & id = 734 HTML Comment Displays a comment on the client. JSP syntax ] - > Example 1 Generated in the client's HTML source code and the same data as above: Example 2 -> Displayed in the client's HTML source code as: Description This annotation and HTML are very similar, that is, it can be seen in "View Source /". The only thing is that you can use expressions in this comment (shown in Example 2) This expression is not different, different from the page, you can use a variety of expressions, as long as it is legal. More please see the expression hidden comment written in the JSP program, but not send it to the customer. JSP syntax <% - Comment -%> example:
CODE:
<% @ Page language = "java"%>
Describe the characters with hidden comment markers to be ignored when JSP compiles. This comment is useful when you want to hide or annotate your JSP program. The JSP compiler does not compile the statement between <% - and -%>, which does not display in the customer's browser, nor does it see the declaration in the JSP program in the source code. Variables and methods JSP grammar <%! Declaration; [declaration;] ...%> <%! Int i = 0;%> <%! Int A, b, c;%> <%! Circle a = NEW CIRCLE (2.0);%> Description Declare the variables and methods you want to use in the JSP program. You must also do this, or you will make mistakes. You can declare multiple variables and methods in one time, as long as you end, you will be legal in Java. When you declare methods or variables, please pay attention to some of the following rules: The statement must be ";" end (Scriptlet has the same rules, but the expression is different). You can use it directly in <% @ Page%> Contains the already declared variables and methods, do not need to be re-declared. A statement is only valid in one page. If you want each page to use some statements, it is best to write them into a separate file, then use <% @ include%> or
[/ b] scripTlet [/ b] contains a valid block. JSP syntax <% code fragment%> example <% string name = null; if (Request.getParameter ("name") == null) {%> < % @ Include file = "error.html"%> <%} else {foo.setname ("name")); if (foo.getname (). EqualsignoreCase ("Integra")) Name = "Acura "; If (name.equalsignorecase (" acura ")) {%> Description A scripTlet can include multiple JSP statements, methods, variables, expressions because we can do the following things: Declaration of variables you want to use or Method (Reference Declaration). Write a JSP expression (reference expression). Writing a JSP statement using any implicit object and any object (if you are using Java language, these statements must follow Java) LANGUAGE Specification,). Any text, HTML tag, JSP element must be executed when JSP receives a customer request outside of Scriptlet, if the scriptlet has the content displayed, these displayed content is existing in OUT objects . The include instruction contains a static file in the JSP, parsing the JSP statement in this file. JSP syntax <% @ include file = "relativeURL"%> example include.jsp: Code:
Date.jsp:
CODE:
<% @ Page import = "java.util. *"%> <% = (New java.util.date ()) .tolocalestring ()%>
Displays in the page: The Current Date and Time Are Aug 30, 1999 2:38:40 Description <% @ include%> The instruction will insert a file containing text or code when the JSP is compiled, when you use <% @ include %> When you do your life, this included process is static. Static container means that this file containing files will be inserted into the JSP file. This containable file can be a JSP file, an HTML file, a text file. If included is a JSP file, the code in this file containing the JSP will be executed. If you just use INCLUDE to include a static file. The result of this containing files will be inserted into the JSP file.
Once the included file is executed, the process of the primary JSP file will be recovered, continue to perform the next line. This is included in the HTML file, JSP file, text file, or just a Java code, but you have to pay attention to this included , HTML>,
, body> tag can not be used in the file, as this will affect the same tag in the original JSP file, which sometimes causes errors. Some <% @ include% > The behavior of the command is based on special JSP compilation conditions, such as: This file must be open to all customers and must be valid, or it has secure restrictions if this containment is changed, including this file The JSP file will be recompiled attributes: file = "relativeurl" This containing file name is generally referring to relative paths, no port, protocol, and domain name, as follows: "Error.jsp" Templates / Onlinestore.html "/beans/calendar.jsp" If this path starts with "/", then this path is primarily referring to the up and down relational path of the JSP application. If the path starts with a file name or directory name, then this path is JSP that is being used. The current path of the file. Page instruction defines global properties in the JSP file. JSP syntax <% @ page [language = "java"] [EXTENDS = "package.class"] [import = "{package.class | package. *} , ... "] [session =" true | false "] [buffer =" none | 8KB | SIZEKB "] [Autoflush =" true | false "] [isthreadsafe =" true | false "] [info =" text " ] [ErrorPage = "RelativeURL"] [contenttype = "MIMETYPE [; charset = characterset]" | "text / html; charSet = ISO-8859-1"] [ISERRPAGE = "true | false"]%> example <% @% @ Page Import = "java.util. *, java.lang. *"%> <% @ page buffer = "5kb" Autoflush = "false"%> <% @ Page ErrorPage = "Erro R.Jsp "%> Description <% @ Page%> The instruction applies to the entire JSP page, and also includes static include files. But <% @ page%> The instruction does not act on dynamic containing files, such asBecause the Import property and the Import statement in Java are almost (refer to Java Language), you can use this property a few times. Whether you put <% @ Page%> instructions in JSP files, its role range It is the entire JSP page. However, for the readability of the JSP program, and good program habits, it is best to put it on the top of the JSP file. Attribute language = "java" declares the type of scripting language, temporarily only "java" extends = " Package.class "Missing the full name of the Java Class, which needs to be added, but you can use it with caution, which will limit the compilation power of JSP. Import =" {package.class | package. *}, ... " A list of imported Java packages, these packages act on blocks, expressions, and declarations. The following packages have been imported at JSP compile, so you don't need to specify: java.lang. * Javax.servlet.jsp. * Javax.servlet.http. * Session = "true | false "Set whether the customer needs http session. (Soced with ASP, it should be unfamiliar with it) if it is true, then Session is useful. If it has false, then you can't use the Session object, and define the
The default MIME type is: text / html, the default character set is ISO-8859-1.
Name Specify parameter name, value specifies parameter value. Calendar of
Tip: In the JSP reference in Sun, if you use
Attributes Page = "{relativeURL | <% = expression%>}" parameter is a relative path, or represents a relative path expression. Flush = "true" Here you must use flush = "true", you can't use false value The default value is false Unable to load applet p> jsp: Fallback> jsp: plugin > Description When the JSP file is compiled, when sending to the browser, the The name of the attribute in the bean is consistent with the parameter name in the Request object. The parameter value transmitted from the customer is generally the character type, which must be converted into other types in the bean. The type of bean property is listed in the table below and their conversion method. Transform strings into other types of methods. Property type method Boolean or boolean java.lang.Boolean.Valueof (string) Byte or byte java.lang. Byte.valueOf (String) char or Character java.lang.Character.valueOf (String) double or Double java.lang.Double.valueOf (String) integer or Integer java.lang.Integer.valueOf (String) float or float java. Lang.float.Valueof (String) long.valueof (String) If there is a nougant value in the parameter value of the Request object, the corresponding bean property will not set any values. Similarly, if there is an attribute in the bean without the corresponding request parameter value, then this attribute is also not set. Property = "PropertyName" [param = "parametername"] Use a parameter value in the request to specify bean A property value. In this syntax, Property specifies the bean's attribute name. PARAM specifies the parameter name in the request. If the bean property is different from the name of the request parameter, then you must specify Property and Param, if they are the same name, then you just need to specify Property is the line. If the value of the parameter is empty (or not initialized), the corresponding bean property is not set. Property = "PropertyName" value = "{string | <% = expression%>}" uses the specified value Set the bean property. This value can be a string or an expression. If this string, it will be converted to the type of the bean property (see the above table). If it is an expression, then its type must be consistent with the type of attribute value to be set. If the parameter value is empty, the corresponding attribute value will not be set. In addition, you can't use Param and Value tips in a