Main Features of JSP

This section describes main features of JSP including scripting elements, built-in objects, directives, JavaBean objects, JSTL, EL and standard actions.

What Are Main Features of JSP? The current release of JSP is JSP 2.3 which supports following main features:

1. Scripting Elements - JSP supports 3 types of scripting elements: declarations, scriptlets and expressions. Scriptlets are most commonly used to enter any code fragments in the default Java language. For example, the following JSP code uses scriptlets to form an if-else flow control with a mix of static data and Java code fragments (not full Java statements):

<% if (Calendar.getInstance().get(Calendar.AM_PM) == Calendar.AM) {%>
Good Morning
<% } else { %>
Good Afternoon
<% } %>

2. Built-in Objects - JSP supports a number of built-in implicit objects that provide you easy access to different parts of the application environment. For example, the following JSP code uses the built-in object "response" to set the "Content-Type" header in the HTTP response message:

<% response.setContentType("text/html;charset=UTF-8"); %>

3. Directives - JSP supports directives as commands to the JSP engine. Commonly used directives are: page, variable, taglib, and include. For example, the following JSP code uses the "page" directive to import a Java class as a data type to the page scope:

%@ page import="javax.servlet.http.Cookie" %>

4. JavaBean - JSP supports JavaBean objects using the "useBean" action element. For example, the following JSP code loads a JavaBean object, sets a property to the object, and retrieves it back later:

<jsp:useBean id="b" class="com.herongyang.CacheBean"/>
<jsp:setProperty name="b" property="text" value="Hello world!"/>
Property from my Bean: <jsp:getProperty name="b" property="text"/>

5. JSTL (JSP Standard Tag Library) - JSP supports JSTL core library and custom tag libraries. For example, the following JSP code uses the "forEach" tag in the JSTL core library to generate dynamic data as an execution loop:

<c:forEach xmlns:c=""
var="counter" begin="1" end="3">

6. EL (Expression Language) - JSP supports EL that allows you to build expressions more powerful and complex than the scripting expression with the default Java language. For example, the following JSP code uses an EL expression to retrieve the value of the first cookie from the HTTP request:

<c:out value="Cookie: ${pageContext.request.cookies[0].value}"/>

7. Standard Actions - JSP supports a number of standard actions that allows to perform some common tasks. For example, the following JSP code uses the "forward" standard action to redirect users to different pages based on an if condition:

<% if (Calendar.getInstance().get(Calendar.AM_PM) == Calendar.AM) {%>
<jsp:forward page="morning.jsp"/>
<% } else { %>
<jsp:forward page="afternoon.jsp"/>
<% } %>

Table of Contents

 About This Book

JSP (JavaServer Pages) Overview

 What Is JSP (JavaServer Pages)

 JSP Releases and Changes

Main Features of JSP

 How JSP Pages Are Processed

 Popular JSP Enabled Web Servers

 Tomcat Installation on Windows Systems

 JSP Scripting Elements

 Java Servlet Introduction

 JSP Implicit Objects

 Syntax of JSP Pages and JSP Documents

 JSP Application Session

 Managing Cookies in JSP Pages

 JavaBean Objects and "useBean" Action Elements

 Managing HTTP Response Header Lines

 Non-ASCII Characters Support in JSP Pages

 Performance of JSP Pages

 EL (Expression Language)

 Overview of JSTL (JSP Standard Tag Libraries)

 JSTL Core Library

 JSP Custom Tags

 JSP Java Tag Interface

 Custom Tag Attributes

 Multiple Tags Working Together

 File Upload Test Application

 Using Tomcat on CentOS Systems

 Using Tomcat on macOS Systems

 Connecting to SQL Server from Servlet

 Developing Web Applications with Servlet

 Archived Tutorials


 Full Version in PDF/EPUB