Notes
Introduction to JSP
What is JSP?
- JSP (JavaServer Pages) = Presentation logic* + Business logic
- Servlet = Business logic* + Presentation logic
- JSP is converted into servlet during execution
- JSP is considered outdated in modern web development
JSP Syntax Elements
1. Directive <%@ ... %>
Instructs JSP engine to process the JSP file.
Types of Directives:
@page
- Controls servlet creation/translation
@include
- Includes JSP/HTML into another JSP
@taglib
- Uses custom/third-party tags in JSP
2. Declaration <%! ... %>
- Declares fields and methods in generated servlet
- Code goes outside the service() method
- Used for instance variables and helper methods
3. Scriptlet <% ... %>
- Contains Java statements executed for each request