Brief introduction of JSP knowledge

  • 2021-07-03 00:44:15
  • OfStack

Hide comments

Written in the JSP program, but not sent to customers.

JSP syntax
< %-- comment --% >
Examples:


<%@ page language="java" %>
<html>
<head><title>A Comment Test</title></head>
<body>
<h2>A Test of Comments</h2>
<%-- This comment will not be visible in the page source --%>
</body>
</html>

Describe

Characters marked with hidden comments are ignored at JSP compile time. This annotation is useful when you want to hide or annotate your JSP program. Isn't the JSP compiler < %--and--% > It will not be displayed in the customer's browser, nor will it be seen in the source code

In < %-- --% > You can write any comment statement, but you can't use "--% > "If you have to use it, please use it"-% > ".
================================================================
Declaration
Declare legal variables and methods in JSP programs

JSP Syntax
< %! declaration; [ declaration; ]+ ... % >
Example


<%! int i = 0; %>
<%! int a, b, c; %>
<%! Circle a = new Circle(2.0); %>

Describe
Declare the variables and methods you will use in JSP programs. You must do the same, or you will make mistakes.

You can declare multiple variables and methods at once, as long as you use "; "The end will do, of course, if these statements are legal in Java.

When you declare a method or variable, please pay attention to the following 1 rules:

The statement must be written with "; "End (Scriptlet has the same rule, but the expression is different).
You can use it directly in the < % @ page % > You do not need to re-declare the declared variables and methods included in.
1 Declaration is valid on 1 page only. If you want to use a few declarations for each page, it is best to write them as a separate file and then use < %@ include % > Or < jsp:include > Element is included.
==================================================================

Expression
Contains 1 expression that conforms to JSP syntax

JSP Syntax
< %= expression % >
Example


<font color="blue"><%= map.size() %></font>
<b><%= numguess.getHint() %></b>.

Describe
The expression element represents an expression defined in the scripting language, which is automatically converted to a string after running, and then inserted into the expression to be displayed in the location of the JSP file. Because the value of this expression has been converted to a string, you can insert this expression in 1 line of text (exactly like ASP).
Keep the following in mind when you use expressions in JSP:
You can't use a semicolon (";") as the terminator of an expression. But the same expression in scriptlet needs to end with a semicolon! View Scriptlet
This expression element can include any expression that is valid in Java Language Specification.
Sometimes expressions can also be used as attribute values for other JSP elements. An expression can become complex and may consist of one or more expressions in the order left to right.


Related articles: