Scriptlet in Java

Scriptlet: A scriptlet can contain any number of language statements, variable or method declarations, or expressions that are valid in the page scripting language.

When the scripting language is set to java, a scriptlet is transformed into a Java programming language statement fragment and is inserted into the service method of the JSP page’s servlet. A programming language variable created within a scriptlet is accessible from anywhere within the JSP page

We can embed any amount of java code in the JSP Scriptlets. JSP Engine places these code in the _jspService() method

Within a scriptlet, you can do any of the following:

  • Declare variables or methods to use later in the JSP page .
  • Write expressions valid in the page scripting language
  • Use any of the implicit objects or any object declared with a <jsp:useBean> element.
  • Write any other statement valid in the scripting language used in the JSP page.

Any text, HTML tags, or JSP elements you write must be outside the scriptlet.

Scriptlets are executed at request time, when the JSP container processes the request. If the scriptlet produces output, the output is stored in the out object.

JSP Syntax-

<% code fragment %>

Leave a Reply

Your email address will not be published. Required fields are marked *