JS in the previous tutorial we have used "out" variables in a scriptlet to produce HTML output. For more complex HTML, we lose many of the advantages of JSP programming if we still use the "out" variable. In fact, we can simply implement scriptlets and HTML blending.
If you want to generate a table in HTML. Creating a table is an ordinary operation, and in practice you may want to generate a table from a SQL table or from a file's line. In order to be as simple as possible, we produce a table that contains numbers from 1 to N. Although the following examples are not very useful, you can learn some skills from them. Here is the JSP's program fragment:
<table border=2>
<%
for (int i = 0; i < n; i++) {
%>
<TR>
<TD>Number</TD>
<td><%= i+1%></td>
</TR>
<%
}
%>
</TABLE>
Before coding, you should first define an integer (int) variable "n", using this variable we want to output "n" Rows of the table. From the above code we can notice that the%> and <% characters appear in the "for" loop, which is to get you back to the HTML and then back to the Scriptlet, which is exactly the combination of scriptlets and HTML.
The code above is really simple: you can write HTML when you exit Scriptlet, and then go back to Scriptlet. Any loop-control expression, such as a "while" or "for" loop, and an "if" statement can control HTML. If the HTML is in a loop, it executes once in each loop.
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.