Scriptlets and Expressions in JSP

By: Sathya Narayana Emailed: 1768 times Printed: 2515 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

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>



JSP Home | All JSP Tutorials | Latest JSP Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Sathya Narayana
Querying Data with the JSTL in JSP
Deleting Data in MySQL
Modifying data and using WHERE clause in MySQL
Querying the Database in MySQL
Inserting Data into Tables in MySQL
Changing the Structure of an Existing Table in MySQL
The Exception Object in JSP
The Application Object in JSP
The Session Object in JSP
The Out Object in JSP
The Response Object in JSP
The Request Object in JSP
Tag Libraries in JSP
Scriptlets and Expressions in JSP
Declarations in JSP

More Tutorials in JSP
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: `java.net.BindException: Permission denied <null>:80
JSP Alert Example
JSP CheckBox Example
Uploading an Image to a Database using JSP
Uploading a file to a server using JSP
A JSP page that gets properties from a bean
The page Directive in JSP
The taglib, tag, include, attribute and the variable Directive in JSP
Declarations in JSP
Scriptlets and Expressions in JSP
Tag Libraries in JSP
The Request Object in JSP
The Response Object in JSP
The Out Object in JSP
The Session Object in JSP

More Latest News
Most Viewed Articles (in JSP )
What are the different scopes in JSP?
JSP Program for display Date
Arithmetic Evaluation Using the Expression Language in JSP
JSP Example to connect to MS SQL database and retrieve records
Embedding java codes in jsp sciptlets
Tags using in jsp
Comparison operators in JSP
Encrypting Passwords in Tomcat using Servlets
Automatically Refreshing a JSP
What is JSP?
Scriptlets and Expressions in JSP
The Application Object in JSP
The Exception Object in JSP
Uploading an Image to a Database using JSP
JSP Alert Example
Most Emailed Articles (in JSP)
NotifyUtil::java.net.ConnectException: Connection refused: connect
Encrypting Passwords in Tomcat using Servlets
Tag Libraries in JSP
What is JSP?
Cookies using JSP or Java Bean
Click to Activate and Use this control
The JSP Program running first Time.
Scriptlets
Server Side Programming
Syntax For JSP Declaratives
Embedding java codes in jsp sciptlets
Tags using in jsp
JSP pages in servlet
Combining Scriptlets with HTML
JSP Directives