Scriptlets and Scriptlet Expressions

Learn about scriptlet, scriptlet expression, and expression language.

We'll cover the following

A JSP is compiled into a servlet, which means that anything that can be done in a servlet can also be done in a JSP. In PlayerServlet, we wrote Java code, while in welcome.jsp, we wrote HTML. Just as HTML can be written in the PlayerServlet class, Java code can be written in welcome.jsp. Java code in a JSP is called a scriptlet.

A disclaimer before we show how to write a scriptlet: this is not recommended practice and should be avoided.

Scriptlet

In a JSP, anything written between the <% %> tags is a scriptlet. We can print something on the console from welcome.jsp as follows:

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.