Scriptlets and Expressions in JSP

By: Sathya Narayana Viewed: 1389 times  Printer Friendly Format    

Scriptlets enclose Java code (on however many lines) that's evaluated within the generated servlet's _jspService() method to generate dynamic content:

// Java code

Take care when using adjacent scriptlet blocks; this code:
<% if(user.isLoggedIn) { %>
<% } %>
<% else { %>
<p>Please log in first...</p>
<% } %>

isn't legal because you've broken the else block into two scriptlets.

Expressions return a value from the scripting code as a String to the page:
<p>Hello there,
<%= userName %>
Good to see you.</p>

Most Viewed Articles (in JSP )

Latest Articles (in JSP)

Comment on this tutorial