Tuesday, 4 December 2012

Using the Scriplet Tag

                       The Scriplet tag allows Java to be mixed with HTML to produce dynamic content.Java code must be embedded within the <%  and %> tag delimiters.Each language statement must end with a semicolon.

<html>
<head>
<title> Simple JSP page </title>
</head>
<body>
<h3>Embedded Java Code within a Web Page </h3>
<p>
<%
for (int i=1;i<7;i++)
{
 out.println("<H"+i+">The Size of H" + i +"</H"+i+">");
 out.println("<br>");
}
%>
</body>
</html>

Description:


  • Type <% to indicate the beginning of the Scriplet tag.
  • Type the applicable Java code after the <% delimiter.
  • Use the out.println method to generate HTML.
  • Type %> to close the Scriplet tag.

The Same program can also be written as :


<html>
<head>
<title> Simple JSP page </title>
</head>
<body>
<h3>Embedded Java Code within a Web Page </h3>
<p>
<%
for (int i=1;i<7;i++)
{
%>
 <H<%=i%>>The Size of H<%=i%> </H<%=i%>>
 <br>
<%
}
%>
</body>
</html>

you can mix HTML and Java code in any combination but you must remember to close the Scriplet tag before you start HTML and then reopen the Scriplet tag when you want to write more Java code.


*********************************OUTPUT****************************************

Embedded Java Code within a Web Page


The Size of H1



The Size of H2



The Size of H3



The Size of H4



The Size of H5


The Size of H6

********************************************************************************



No comments:

Post a Comment