Nearby lessons

1 of 30

JSP - Introduction

📌 What You Will Learn
  • 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

ServletsJSP
Best for processing logicBest for presentation logic
Verify user credentialsDisplay a login page
Check account balanceDisplay inbox page
Collect data from databaseDisplay 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

TechnologyVersion
JEE (Java Enterprise Edition)7
Servlets3.1
JSP2.3
JSTL1.2
EL (Expression Language)3.0
📝 Key Takeaways
  • 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

🧠 Test Your Knowledge

3 Questions
Progress: 0 / 3