Basic knowledge of JSP database grammar detailed

Source: Internet
Author: User
Tags expression html tags reference valid client
js| Data | database | detailed | grammar

HTML Annotation
Displays a comment on the client.

JSP syntax
!--comment [<%= expression%>]-->
Example 1
!--This file displays the user login screen-->
Generate the same data as above in the client's HTML source code:

!--This file displays the user login screen-->
Example 2
!--This page is loaded on <%= (new Java.util.Date ()). toLocaleString ()%>-->
Displayed in the client's HTML source code as:

!--This page is loaded on January 1, 2000-->
Describe
This annotation is similar to HTML in that it can be seen in "viewing source code."

The only difference is that you can use an expression in this annotation (example 2). The expression is variable, and the page is different, and you can work with various expressions, as long as they are legal. For more, see expressions

Hide Annotations
Write in the JSP program, but not to the customer.

JSP syntax
<%--Comment--%>
Example:
<%@ page language= "java"%>
<body>
<%--This comment'll is visible in the page source--%>
</body>

Description
Characters marked with hidden annotations are ignored when the JSP is compiled. This annotation is useful when you want to hide or annotate your JSP program. The JSP compiler does not compile the statements between <%--and--%>, it does not appear in the client's browser, and it is not seen in the source code

Statement
Declaring legitimate variables and methods in a JSP program

JSP Syntax
<%! Declaration; [Declaration;] + ...%>
Example
<%! int i = 0; %>
<%! int A, b, C; %>
<%! Circle a = new Circle (2.0); %>
Describe
Declare the variables and methods that you will use in your JSP program. You must do the same, or you will make mistakes.

You can declare multiple variables and methods at once, as long as the ";" At the end of the line, of course, these statements in Java if legitimate.

When you declare a method or variable, be aware of some of the following rules:

The statement must be ";" The end (Scriptlet has the same rule, but the expression is different).
You can directly use the declared variables and methods that are included in the <% @ Page%>, and do not need to declare them again.
A declaration is valid only in one page. If you want to use a few statements for each page, it's best to write them in a separate file, and then include the <%@ include% or <jsp:include > elements.

An expression

Contains an expression that conforms to the JSP syntax

JSP syntax
<%= expression%>
Example
<font color= "Blue" ><%= map.size ()%> </font>
<b> <%= numguess.gethint ()%> </b>.
Describe
An expression element represents an expression that is defined in a scripting language, automatically converted to a string after it is run, and then inserted into the location of the JSP file to display the expression. Because the value of this expression has been converted to a string, you can insert the expression in one line of text (in the same way as an ASP).

When you use an expression in your JSP, keep the following points in mind:

You cannot use a semicolon (";") as the terminator of an expression. But the same expression used in scriptlet needs to end with a semicolon! View Scriptlet
This expression element can include any expression that is valid in the Java Language specification.
Sometimes an expression can also be a property value of another JSP element. An expression can become complex, and it may consist of one or more expressions, the order of which is left to right.

Scriptlet

Contains a valid program segment.

JSP syntax
<% Code Fragment%>
Example
<%
String name = NULL;
if (Request.getparameter ("name") = = null) {
%>
<%@ include file= "error.html"%>
<%
} else {
Foo.setname (Request.getparameter ("name"));
if (Foo.getname (). Equalsignorecase ("Integra"))
Name = "Acura";
if (Name.equalsignorecase ("Acura")) {
%>
Describe
A scriptlet can contain multiple JSP statements, methods, variables, expressions

Because of scriptlet, we can do the following things:

Declare the variable or method (reference declaration) that will be used.
Write a JSP expression (a reference expression).
Use any suppressed objects and any objects declared with the <jsp:useBean>
Write JSP statements (if you are using the Java language, these statements must conform to the Java Language specification).
Any text, HTML tags, JSP elements must be outside the Scriptlet
When the JSP receives the customer's request, the scriptlet is executed, and if Scriptlet has the displayed content, the displayed content is present in the Out object.

[1] [2] [3] [4] Next page



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.