A Scriptlet is a piece of raw Java code embedded in a JSP file which gets executed in line with the JSP output.
A Scriptlet is a piece of raw Java code embedded in a JSP file which get executed in line with the JSP output (which is usually HTML). It's recognizeable by the Java code between the <%
and %>
tags. Its use is since JSP 2.0 (2003) as per the JSP coding conventions discouraged in favor of tag libraries like JSTL and expression language EL to control the flow of JSP output. The real business job such as preprocessing (e.g. loading data from DB) and postprocessing (e.g. saving submitted form) should be done in a servlet.
Scriptlets are these days considered old school and a bad practice. They are however still useful for quick prototyping and testing, for example to quickly prepare/stub values in top of JSP so that JSTL tags and EL expressions further down in the JSP page can quickly be prototyped/tested.