Scriptlet
Definition:
Scriptlet is similar to the Expression without the equal sign "=". You can insert any plain Java code inside the scriptlet. Because of mixing between Java code and HTML is difficult to maintain so scriptlet is not recommended to use anymore. Here is the syntax of the scriptlet:
Scriptlet is similar to the Expression without the equal sign "=". You can insert any plain Java code inside the scriptlet. Because of mixing between Java code and HTML is difficult to maintain so scriptlet is not recommended to use anymore. Here is the syntax of the scriptlet:
Syntax :
<% java code %> |
Description:
1. JSP Scriptlets begins with <% and ends %>
2. JSP Engine places these code in the _jspService() method
3. A scriptlet doesn't contribute any HTML.
4. Every statement inside scriptlet should ends with semicolon.
5. By itself a scriptlet does not generate HTML. If a scriptlet wants to generate HTML, it can use a variable called "out".here “out “ is a implicit object we will discuss later.
Ex: out.println(“<table><tr><td>”);
Out.println(“MYJAVAHUB</td></tr></table>”);
Scriptlet hit count example :
Write a jsp to display hit count of the jsp ?
Test.jsp
<%! int count=0; %> <% count ++; out.println("<h2>The hit count is : :"+count+"</h2>"); %> |
Output: