JSP, EL, JSTL, Form Taglib, and FMT Complete Tutorial
Introduction to JSP
JSP (Jakarta Server Pages) is a server-side technology that helps create dynamic web pages by
embedding Java code in HTML. JSP files are compiled into Servlets by the server and executed to
generate HTML output for the browser.
JSP Basics
### How JSP Works
1. **Translation:** JSP is converted into a Servlet.
2. **Execution:** The Servlet executes, producing HTML as output.
### JSP Scripting Elements
- **Scriptlet (`<% ... %>`):** Embed Java code.
- **Expression (`<%= ... %>`):** Print values directly.
- **Declaration (`<%! ... %>`):** Define variables and methods.
### JSP Directives
- `<%@ page ... %>`: Page settings (e.g., imports).
- `<%@ include ... %>`: Include files.
- `<%@ taglib ... %>`: Load tag libraries.
### JSP Implicit Objects
- `request`, `response`, `out`, `session`, `application` etc.
### JSP Actions
- ``, ``, ``, `` etc.
Expression Language (EL)
### Purpose
EL is used to simplify access to application data stored in scopes. Syntax: `${...}`
### EL Implicit Objects
- `pageScope`, `requestScope`, `sessionScope`, `applicationScope`
- `param`, `paramValues`
- `header`, `cookie`
### Features
- Property access: `${[Link]}`
- Null safety (prints nothing if null)
- Operators: Arithmetic, Logical, Relational
- `empty` operator to check null/empty
JSP Standard Tag Library (JSTL)
### Setup
Add JSTL JAR file and include with:
<%@ taglib uri="[Link] prefix="c" %>
### Common JSTL Core Tags
- ``: Safe printing
- ``: Conditional rendering
- ` `: If-Else logic
- ``: Loops
### Example
Spring Form Tag Library
### Setup
<%@ taglib uri="[Link] prefix="form" %>
### Key Tags
- ``: Main form container (`modelAttribute` links to Java object).
- ``, ``, ``: Input fields.
- ``, ``, ``: Choices.
- ``: Show validation errors.
### Example
Username:
JSTL Formatting (FMT) Library
### Setup
<%@ taglib uri="[Link] prefix="fmt" %>
### Number Formatting
### Date Formatting
### Internationalization
Resource bundles allow multiple languages.
messages_en.properties:
greeting=Hello!
messages_hi.properties:
greeting=■■■■■■!
Usage:
Conclusion
By mastering JSP basics, EL for clean data access, JSTL for control flow, Spring Form tags for
form handling, and FMT for formatting and i18n, you can build powerful, professional, and
maintainable web applications.