Search⌘ K
AI Features

Scriptlets and Scriptlet Expressions

Explore how to include Java code in JSP pages using scriptlets and scriptlet expressions. Understand the syntax and functionality for displaying dynamic content and why using scriptlets is discouraged in favor of separating business logic from views.

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. ...