MAHENDRA ENGINEERING
COLLEGE
PRESENTATION TOPIC : JSP BASICS
STUDENT : Mohammad Sikkander N
SUBJECT : Advanced Java Program
JavaServer Pages (JSP)
Basics
Scripting Elements, Directives, Action Tags & Implicit Objects
What is JavaServer Pages?
JSP is a powerful server-side technology that enables developers to create
dynamic web pages by seamlessly blending Java code with HTML
markup.
This technology provides four essential building blocks for web application
development:
Scripting Elements - embed Java code directly
Directives - configure page behaviour
Action Tags - perform dynamic operations
Implicit Objects - access built-in functionality
Scripting Elements
Scripting elements allow you to embed Java code directly into your JSP pages, providing three distinct ways to integrate server-
side logic.
Scriptlet Expression Declaration
<% ... %> <%= ... %> <%! ... %>
Contains executable Java Outputs a single value or expression Declares variables and methods at
statements and logic blocks. result to the page. the class level.
<%! int count = 0; %>
<% count++; %>
Page visited: <%= count %> times
JSP Directives Overview
Directives provide global instructions to the JSP container, controlling
how the entire page is processed and rendered.
01 02
Page Directive Include Directive
Defines essential page-level Incorporates content from other
settings including imports, content files during the translation phase,
types, and error handling creating a unified page.
configuration.
03
Taglib Directive
Enables the use of custom tag libraries and JSTL for enhanced
functionality.
Page Directive in Detail
Syntax Structure Practical Example
<%@ page attribute="value" %> <%@ page import="[Link]" %>
Current Date: <%= new Date() %>
Essential Attributes
import ³ Import Java classes and packages
contentType ³ Set MIME type and character encoding
errorPage ³ Define error handling page
isErrorPage ³ Designate as error handler
Include & Taglib Directives
Include Directive
<%@ include file="[Link]" %>
Inserts the content of another JSP file at translation time, creating a
single compiled unit.
Taglib Directive
<%@ taglib uri="[Link]
prefix="c" %>
Enables the use of custom tags and JSTL libraries for enhanced
page functionality.
Action Tags Introduction
Action tags use XML-style syntax to perform runtime operations, offering
a cleaner alternative to scriptlets.
Standard Action Tags
<jsp:include> - includes pages at request time
<jsp:forward> - forwards requests to other resources
<jsp:useBean> - creates and manages JavaBeans
Action Tag Examples
Include Action Forward Action UseBean Action
<jsp:include page="[Link]" <jsp:forward page="[Link]" <jsp:useBean id="user"
/> /> class="[Link]"
scope="session" />
Dynamically includes content at Transfers control to another
runtime, allowing for conditional resource whilst maintaining request Creates or retrieves JavaBean
inclusion. data. instances with specified scope.
JSP Implicit Objects
JSP automatically provides nine predefined objects that offer immediate access to common web application functionality.
request response
HTTP request data HTTP response object
page + others session
pageContext, config, exception User session data
out application
Output stream Application context
Putting It All Together
Practical Example Key Takeaways
Scripting Elements embed Java code seamlessly
Welcome, <%= [Link]("username")
Directives configure page-level behaviour
%><br>
Session ID: <%= [Link]() %><br> Action Tags provide clean runtime operations
Server Info: <%= [Link]() %> Implicit Objects offer immediate web functionality
Master these four concepts to build robust, dynamic web
applications with JSP.