JSP Tutorials - Herong's Tutorial Examples

http://www.herongyang.com/JSP

Copyright © 2017 by Dr. Herong Yang. All rights reserved.

JSP Tutorial This free book is a collection of notes and sample codes written by the author while he was learning JSP. Topics include attachment, content-disposition, cookie, custom tag, debugging, expression language, file upload, header lines, HTTP, JavaBeen, JavaSever Page, JSP, JSTL, JSTL-EL, localization, MIME, pageContext, Request, Response, Servlet, session, Taglib, TagSupport, TLD, Tomcat, Unicode, useBean, UTF-8, XML.

Table of Contents

About This Book

JSP (JavaServer Pages) Overview

What Is JSP (JavaServer Pages)?

Main Features of JSP 2.1

How JSP Pages Are Processed?

Popular JSP Enabled Web Servers

Tomcat 7 Installation on Windows Systems

Downloading and Installing Tomcat 7

Launching Tomcat 7 Server

Verifying Tomcat 7 Server

Setting Up Tomcat 7 Server Admin Access

Reviewing Tomcat 7 Server Status Page

Tomcat Web Application Manager

My First HTML Page - hello.html

My First JSP Page - hello.jsp

JSP Scripting Elements

What Are Scripting Elements?

Converting JSP Pages with Scripting Elements

Example JSP Page with Scripting Elements

Example Java Class Converted from a JSP Page

Mixing Static Data with Scriptlets for Compound Statements

Java Servlet Introduction

What Is Servlet?

Creating and Deploying a Servlet on Tomcat

Relationship between Servlet and JSP

Modifying the Servlet Converted from a JSP Page

JSP Implicit Objects

What Are Implicit Objects

Information of JSP Execution Context

Information from "request" Object

Methods Supported by the "session" Object

Syntax of JSP Pages and JSP Documents

Syntactic Elements of a JSP Page

JSP Document - JSP Page in XML Format

Writing Scriptlet Element in XML Format

Writing Directive Element in XML Format

Writing Action Element in XML Format

"include" Directive and Action Elements

Execution Result of CurrentTime.jspx

JSP Application Session

What Is a Session?

The "session" Implicit Object

Passing Values between JSP Pages

Testing Result of RegForm.jspx

Using Perl LWP Package for Debugging

Managing Cookies in JSP Pages

What Is a Cookie?

Sending and Receiving Cookies in JSP Pages

Persistent Cookies Stored on Hard Disk

Persistent Cookie Test Example

Dumping HTTP Response with Cookies

JavaBean Objects and "useBean" Action Elements

What Is a JavaBean?

"jsp:useBean" Action Elements

Servlet Class Converted from UseBean.jspx

Setting and Getting JavaBean's Properties

Using JavaBean Objects in Scripting Elements

Using Java Objects as JavaBeans

getProperty() Error on Tomcat 7

Refreshing Loaded JavaBean Classes

Importing Unnamed Package Class Error

Using JavaBean without Import Element Error

Creating JavaBean Classes in Named Packages

"NoClassDefFoundError" Exception

Managing HTTP Response Header Lines

What Is HTTP Response?

HTTP Response Header Lines

Controlling Response Header Lines

Viewing Response Header Lines

Response Header Lines of Static Files

Response Header Lines Controlled by "page" Directive

Response Header Lines Controlled by response Object

Accessing File System from JSP Pages

Returning non-HTML Response Body

Returning Attachments for Web Download

Non-ASCII Characters Support in JSP Pages

Characters Traveling from JSP Files to Browser Screens

Handling ASCII Characters in JSP Pages

Presenting Non ASCII Characters in HTML Documents

Entering Non ASCII Characters in JSP Pages

Java Strings as non-Unicode Encoded Byte Sequences

Java Strings as Unicode Encoded Byte Sequences

Entering Non-ASCII Characters as Static Text

Static HTML Text in HTML Page

Static HTML Text in JSP Page in Standard Syntax

Static HTML Text in JSP Page in XML Syntax

Supporting Characters in Multiple Languages

Performance of JSP Pages

Performance of Calculating Prime Numbers

Performance of Loading JSP Pages

EL (Expression Language)

What is EL (Expression Language)?

EL Expression Types and Usage

Literal Data and Named Variables

Basic Operators and Operations

Predefined Implicit Objects

Collection Elements and Object Properties

Expression Examples in Static Text

Expression Examples in Static Text - Result

EL Variables Are pageContext Attributes

Overview of JSTL (JSP Standard Tag Libraries)

What is JSTL?

Installing GlassFish JSTL 1.2 on Tomcat 7

"Hello world!" with JSTL

JSTL in XML Style JSP Pages

General Syntax of JSTL Tags

NoClassDefFoundError - LoopTag/ForEachTag

Installing JSTL 1.2 API JAR File

JSTL Example - Loop Tag on Map Objects

JSTL Core Library

What Is JSTL Core Library?

c:out Action Tag

c:out Action Tag with EL Expressions

c:set Action Tag

c:if Action Tag

c:choose Action Tag

c:forEach Action Tag

c:forTokens Action Tag

Example - Dumping EL Implicit Objects

Example - Calculating Prime Numbers

JSP Custom Tags

What Is Custom Tag?

Creating and Using Custom Tags

My First Custom Tag - hy:hello

How Custom Tag Works

JSP Java Tag Interface

javax.servlet.jsp.tagext.* Package

javax.servlet.jsp.tagext.IterationTag Interface

IterationTag Interface Test Class - TraceTag.java

IterationTag Interface Test JSP - TraceTagTest.jspx

Servlet Class Converted from JSP - TraceTagTest_jsp.java

TagSupport Class - Dummy Implementation of IterationTag

Custom Tag Attributes

Tag Attributes Are Tag Object Properties

Setter Method Example - EchoTag.java

Value Type Conversion

Value Type Conversion Example - AttValueTag.java

Accepting EL Expressions

Accepting EL Expression Example

Passing Expression as String Example

Using jsp:attribute Action Elements

Multiple Tags Working Together

Nested Tags Example - Break Tag for Loops

Sharing Data with Other Tags

File Upload Test Application

RFC 1867 - Form-based File Upload in HTML

Code 1 - Display Options - UploadInit.html

Code 2 - Display Form - UploadForm.jspx

Code 3 - Dump File - UploadDump.jspx

Test 1 - GET Method - Failed

Test 2 - POST Method - Successful

Code 4 - Save File - UploadSave.jspx

Test 3 - Save File - Successful

Code Review - UploadSave.jspx

Outdated Tutorials

Outdated: Installing Tomcat 4.1.18

Outdated: Java Class Converted by Tomcat 4.1.18

Outdated: Hijacking Servlet Converted from JSP

Outdated: Using Perl LWP::Debug Module to Debug

Outdated: Installing JSTL 1.0 Apache Implementation

Outdated: Upgrade JDK 1.3 to JDK 1.4 on Tomcat 4.1

Outdated: Compilation Errors with JDK 1.4

Outdated: Using JavaBean without Import Element Error

Outdated: Installing Tomcat 5.5.7

References

PDF Printing Version

Keywords: JSP, JavaServer Page, Web, Tutorial