Another important syntax for JSP is tags. JSP tags does not use <%, but only the < character. JSP tag is a bit like HTML tag. JSP tags can have a “start tag”, a “tag body” and an “end tag”. Both the start and end signs can use the name of the sign, which is enclosed in the < and > characters. The ending sign is the character < followed by a backslash (/). This flag name has an embedded colon (:) character inside, where the part before the colon describes the type of flag. For example:
<some:tag>
body
</some:tag>
If the flag does not need a body, the start and end flags can be combined, for example:
<some:tag/>
Here we use a / > instead of the > character, so that we can quickly end the flag without requiring an entity. This syntax is the same as that of XML.
Flags can be divided into two types: one is reproduced from an external flag library, and the other is a predefined flag. The predefined flags start with the jsp: character. For example, jsp:include is a predefined flag used to include other web pages.
In the previous tutorial, we have learned “include directive”. In fact, it is very similar to jsp:include. Instead of loading the text of the included file in the original file, they call the included flag at run time. The following is an example of using jsp:include:
<HTML>
<BODY>
Going to include hello.jsp…<BR>
<jsp:include page=”hello.jsp”/>
</BODY>
</HTML>
Now change the “jsp:include” in the above code to “jsp:forward” to see what the difference is. In fact, these two predefined flags are very useful.
Give the exercise of this section again, and write a JSP to modify an included file according to a boolean variable. Here’s a hint. You need to use the mixed programming of HTML and scriptlets to handle JSP flags.