JSP SCRIPLETS
JSP Syntax: <% code %>
XML Syntax: <jsp: scriptlet > code </jsp:scriptlet>
XML Syntax: <jsp: scriptlet > code </jsp:scriptlet>
Scriptlets are the most common JSP syntax element. As you have studied above, a
scriptlet is a portion of regular Java code embedded in the JSP content within <% ...
%> tags. The Java code in scriptlets is executed when the user asks for the page.
Scriptlets can be used to do absolutely anything the Java language supports, but some
of their more common tasks are:
scriptlet is a portion of regular Java code embedded in the JSP content within <% ...
%> tags. The Java code in scriptlets is executed when the user asks for the page.
Scriptlets can be used to do absolutely anything the Java language supports, but some
of their more common tasks are:
• Executing logic on the server side; for example, accessing a database.
• Implementing conditional HTML by posing a condition on the execution of
portions of the page.
• Looping over JSP fragments, enabling operations such as populating a table with
dynamic content.
• Implementing conditional HTML by posing a condition on the execution of
portions of the page.
• Looping over JSP fragments, enabling operations such as populating a table with
dynamic content.
A simple use of these scriptlet tags is shown in Example 3.2. In this example you
need to notice the two types of data in the page, i.e., static data and dynamic data.
Here, you need not to worry too much about what the JSP page is doing; that will be
covered in later chapters.
need to notice the two types of data in the page, i.e., static data and dynamic data.
Here, you need not to worry too much about what the JSP page is doing; that will be
covered in later chapters.
Example 3.2 simpleDate.jsp
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Final//EN">
<HTML>
<HEAD>
<TITLE>A simple date example</TITLE>
</HEAD>
<BODY COLOR=#ffffff>
The time on the server is
<%= new java.util.Date() %>
</BODY>
</HTML> Scriplets
When the client requests this JSP page, the client will receive a document as HTML.
The translation process used at server is displayed in Figure 2.
<HTML>
<HEAD>
<TITLE>A simple date example</TITLE>
</HEAD>
<BODY COLOR=#ffffff>
The time on the server is
<%= new java.util.Date() %>
</BODY>
</HTML> Scriplets
When the client requests this JSP page, the client will receive a document as HTML.
The translation process used at server is displayed in Figure 2.
No comments:
Post a Comment