Tuesday, October 20, 2009

JSP - embedding scriptlets inside and around html

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
   "http://www.w3.org/TR/html4/loose.dtd"> 
 
<html> 
    <head> 
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
        <title>JSP Page</title> 
    </head> 
    <body> 
        <% 
        // if you need to accomplish a repetitive task 
        // like creating a list of 1,000 numbers and 
        // putting them in a bulletted list then 
        // keep in mind that scriptlets can be your 
        // friend. 
 
        // You notice below that the for loop spans several 
        // pieces of the scriptlet 
        %> 
        <ul> 
        <% 
        for (int i=0; i<1000; i++) {
        %> 
            <li><%= i %></li> 
        <% 
        }
 
        %> 
        </ul> 
        
    </body> 
</html> 
<!-- 
0 
1 
2 
3 
... 
[SNIP] 
... 
998 
999 
--> 
 
 

No comments:

Post a Comment