JSP Page

Last Updated : 16 May, 2026

JavaServer Pages (JSP) is a server-side technology used to create dynamic web pages using Java. A JSP page is a combination of static content and JSP elements that generate dynamic output. It processes user requests and sends the response back to the browser.

  • It is converted into a Servlet internally before execution.
  • JSP elements help control logic, flow, and data handling.

Types of JSP Elements

JSP elements are used to add dynamic behavior and control the execution of the page.

types_of_jsp_elements
JSP Elements

Directive Elements

Used to provide instructions to the JSP container during the translation phase (before execution).

  • Do not produce output directly
  • Affect overall structure and behavior of JSP page
  • Applied before JSP is converted into Servlet

Types of Directives

1. Page Directive

  • Defines page-level settings
  • Controls session usage, error handling, buffering

Syntax:

<%@ page attribute="value" %>

2. Include Directive

  • Includes file at translation time
  • Static inclusion (merged before execution)

Syntax:

<%@ include file="header.jsp" %>

3. Taglib Directive

  • Declares custom tag libraries
  • Used in JSTL and frameworks

Syntax:

<%@ taglib uri="uri" prefix="prefix" %>

2. Action Tags

Used to perform runtime operations and interact with other resources.

  • Executed at request time
  • Can generate dynamic content

Types of Action tag

  • <jsp:forward>: Forwards the request and response to another resource (JSP/Servlet)
  • <jsp:include>: Includes another resource dynamically at runtime
  • <jsp:useBean>: Creates or locates a JavaBean object
  • <jsp:setProperty>: Sets the value of a property in a JavaBean
  • <jsp:getProperty>: Retrieves and displays the value of a bean property
  • <jsp:param>: Passes parameters to another resource (used with forward/include)
  • <jsp:plugin>: Embeds external components like applets
  • <jsp:fallback>: Displays a message if the plugin fails to run

3. Scripting Elements

Used to write Java code inside JSP.

  • Allows embedding Java logic directly
  • Executed inside generated Servlet

Types of Scripting elements

1. Scriptlet Tag

  • Contains Java statements
  • Executes inside _jspService()

Syntax:

<%
int a = 10;
%>

2. Expression Tag

  • Prints value directly
  • Automatically converts to out.print()

Syntax:

<%= a %>

3. Declaration Tag

  • Declares variables/methods
  • Placed outside _jspService()

Syntax:

<%! int a = 10; %>

4. Expression Language (EL)

Simplifies accessing data from objects.

  • No need to write Java code
  • It Improves readability

Syntax:

${user.name}

Advantages of JSP Page Elements

  • Makes code easy to understand and manage
  • Helps in creating dynamic web pages
  • Reduces use of complex Java code
  • Supports code reusability
Comment