scriptlet Tag

The scriptlet tag is the most important tag in the JSP specification since it enables the actual embedding of Java code within an HTML page. The Java code within the scriptlet tag is put by the JSP parser in the service() method of the resultant servlet generated.

Structure of the scriptlet Tag

The structure of the scriptlet tag is as follows:

<% 
// write all the Java statements
%>

or

<jsp:scriptlet> 
// java code
</jsp:scriptlet>

The Java code within the scriptlet tag is placed in the service() method of the servlet generated from the JSP. Any HTML code before or after these tags is converted into out.println(...) statements.

This example represents the true power of JSP tags:

 <BODY> <!--list the names of the books in the shop ...

Get Sams Teach Yourself BEA WebLogic Server 7.0™ in 21 Days now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.