Nearby lessons
1 of 30JSP - Introduction
- Understand why JSP was introduced
- Know the difference between Servlet and JSP
- Learn the JSP technology versions
JSP (JavaServer Pages) is a technology for building dynamic web pages using a combination of HTML and Java. It was introduced by Sun Microsystems in 1999 to simplify web development by separating presentation logic from business logic.
Why JSP Was Introduced
Sun introduced Servlet technology in 1997. It is excellent for processing logic (verifying users, checking account balances, collecting data from databases) but is not suitable for presentation logic.
Even for small outputs, writing presentation code with Servlets requires huge amounts of Java code and strong Java knowledge. To solve this, Sun introduced JSP Technology in 1999.
JSP is designed for presentation logic — displaying pages to the end user.
Servlet vs JSP
| Servlets | JSP |
|---|---|
| Best for processing logic | Best for presentation logic |
| Verify user credentials | Display a login page |
| Check account balance | Display inbox page |
| Collect data from database | Display error pages |
Important Rules
- Servlets: Do not write presentation logic (no
out.println()statements). If you do, you are doing it wrong. - JSP: Do not write business/processing code. JSPs should contain only presentation logic. If you embed Java code here, you are doing it wrong.
Both Servlets and JSPs are part of Java Enterprise Edition (JEE / J2EE).
Technology Versions
| Technology | Version |
|---|---|
| JEE (Java Enterprise Edition) | 7 |
| Servlets | 3.1 |
| JSP | 2.3 |
| JSTL | 1.2 |
| EL (Expression Language) | 3.0 |
- JSP is best suited for presentation logic (the View layer)
- Servlets are best suited for processing logic (the Controller layer)
- Never mix business code in JSP or presentation code in Servlets