Scriptlets and Expressions in JSP
By: Sathya Narayana 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) { %>
<p>Hi!</p>
<% } %>
<% else { %>
<p>Please log in first...</p>
<% } %>
isn't legal because you've broken the else block into two scriptlets.
Expressions
Expressions return a value from the scripting code as a String to the page:
<p>Hello there,
<%= userName %>
Good to see you.</p>
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview