DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • A Systematic Approach for Java Software Upgrades
  • Java EE 6 Pet Catalog with GlassFish and MySQL
  • How To Check for JSON Insecure Deserialization (JID) Attacks With Java
  • Enterprise RIA With Spring 3, Flex 4 and GraniteDS

Trending

  • Data Integration Landscape 2026: Event Streaming, API, and Batch in the Era of Agentic AI
  • Beyond @Transactional: Solving the Dual-Write Problem in Distributed Microservices
  • Why AI Agents Need a Shared Enterprise Ontology
  • Designing Frontend Applications for Failure, Not Just Success

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. Java
  4. An Intro to JSP, JSF, and EL

An Intro to JSP, JSF, and EL

Let's talk about accessing HTTP objects using JSP, the newer and preferred JSF, and how to use Expression Language in your Java EE projects.

By 
Alex Theedom
·
Updated Nov. 24, 17 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
14.7K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

In this article, I am going to take a look at JavaServer Pages (JSP) and Expression Language (EL) and then relate it to JavaServer Faces (JSF). I will talk about how to access HTTP objects directly in JSP and JSF code, and you will see some examples of the syntactic difference between them.

JSP Is Legacy Technology

JSP is Java EE’s legacy web programming technology, which was released in the first version of J2EE back in 1999. Later it was replaced in 2003 by JSF, but its development continued with the latest version 2.3, released in Java EE 7. As of yet, it has not been deprecated.

JSF Is Preferred

Even though JSF has overtaken JSP as the preferred option, there are still many applications that use JSP, and it is very likely that you will come across such applications for quite a few years to come, so it’s worth having an appreciation of this technology.

Dynamic Java Web Applications

JSP is a server-side technology that allows a developer to create dynamic Java web application. JSP can be thought of as an extension to Servlet technology because it provides features to easily create user views. JavaServer Pages consists of HTML code but it allows Java code inclusions for dynamic content creation. Since web applications contain a lot of user screens, JSPs are used a lot in web applications.

Bridge the Gap Between Java and HTML

To bridge the gap between Java code and HTML in JSP, it provides additional features such as JSP Tags, Expression Language, and Custom Tags. This makes it easier to understand, and it helps a web developer quickly develop JSP pages. However, most of the time, we use JSP for view generation only and all the business logic is present in servlet code, Enterprise Java Beans, or model classes.

It is a much less sophisticated view rendering language compared with JSF and does not benefit from the advantage brought by components. However, the separation of view logic and business logic is not always kept so clear. JSP Scriptlets allow Java code to be written directly in the view logic. This clouds the separation.

Inline Java

Such Java code is entered directly in the JSP page between rocket and percentage  <%…%>

JSP Code Example

Here, we are using Java code to access the HTTPServerRequest object in order to retrieve the query parameter named id and password.

Mixing this kind of logic with view technologies is bad practice. This is why modern Java EE applications opt not to use JSP but instead use the better structured component-based JSF language.

JSP Implicit Objects

JSP implicit objects are created by the servlet container while translating JSPs to Servlets. These are mainly related to HTTP objects and scopes. We can use implicit objects in JSP directly in scriptlets, as shown in the above code snippet, to access the values related to the current scope or HTTP objects.

In the following code snippet, we are referencing the HTTP request objects to obtain the context path.

<%=request.contextPath %>


Examples of other implicit JSP objects are request, response, pageContext, and application.

To complicate matters further, Expression Language has its own implicit objects that are similarly name to those available in JSP and relate to the same HTTP objects and scopes.

${request.contextPath}


Examples of other EL implicit objects: request, requestScoped, pageContext, applicationScoped

Here we are obtaining the context path from the HTTP request object, just as we did in the JSP example before. Note that some of the objects are named differently and different syntax is used.

Using EL in JSP and JSF

Let’s widen the topic slightly and look at how we use Expression Language in JSP and JSF.

The following code snippet shows the use of EL in a JSP:

  • Implicit objects: ${request.contextPath}
  • Bean property: ${book.title}

And the following code snippet shows that use of EL in a JSF:

  • Implicit objects: #{request.contextPath}
  • Bean property: #{book.title}

In both cases, the object reference is named the same and references the same object. The only difference is the syntax used to reference the instance. JSP uses the dollar sign while JSF uses the hash. The bean name is referenced by using the class name with the first letter in lowercase (unless another name has been explicitly defined in the named annotation).

And finally, let’s see just a little of the syntax that we use in Expression Language.

  • Logical operators
  • [], (), –, < = >, eq ne, || and more
  • and, not, instanceof, true, mod and more
  • ${not empty book.title}

As you might expect, it is very familiar. We have the standard logical operators that validate equality and perform mathematical operations. Additionally, we are given some syntactic sugar over compound operations such as the not empty operation we see here.

Further Reading

How about learning a little about Context and Dependency Injection (CDI) and Enterprise Java Beans (EJB)? These are two core technologies.

I have recently posted a mini-series of blogs taking a look at JAX-RS. They discuss how to manage bean validation failure, work with Consumers and Producers, and how to create JAX-RS Resource Entities.

There are two deep dive series on JAX-RS topics:

  • What are JAX-RS annotations? A deep dive looking at the annotations most commonly used when developing REST endpoints.
  • What is the @Context annotation used for? A deep dive into the many uses of the @Context annotation.
Object (computer science) Java (programming language) application Spring Framework Java EE

Published at DZone with permission of Alex Theedom. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • A Systematic Approach for Java Software Upgrades
  • Java EE 6 Pet Catalog with GlassFish and MySQL
  • How To Check for JSON Insecure Deserialization (JID) Attacks With Java
  • Enterprise RIA With Spring 3, Flex 4 and GraniteDS

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook