Java Topics
JSP Tags
Last Updated : 26 May, 2026
title: JSP Tags
title: JSP Tags description: JSP ke standard tags aur JSTL
JSP mein alag-alag types ke tags hote hain jo HTML mein Java functionality add karte hain.
1. JSP Scripting Elements
Scriptlet Tag <% %>
Java code likhne ke liye.
<%
String name = request.getParameter("name");
int age = Integer.parseInt(request.getParameter("age"));
if (age >= 18) {
out.println("<p>Adult hai</p>");
} else {
out.println("<p>Minor hai</p>");
}
%>Expression Tag <%= %>
Value directly print karne ke liye. Semicolon mat lagao.
<h1>Hello, <%= request.getParameter("name") %></h1>
<p>Date: <%= new java.util.Date() %></p>
<p>5 + 3 = <%= 5 + 3 %></p>Declaration Tag <%! %>
Variables aur methods declare karne ke liye (instance level).
2. JSP Directive Tags <%@ %>
Page Directive
<%@ page language="java"
contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"
import="java.util.*"
errorPage="/error.jsp"
isErrorPage="false"
session="true" %>Include Directive — Static include
<%@ include file="header.jsp" %>
<h1>Main Content</h1>
<%@ include file="footer.jsp" %>Taglib Directive — JSTL use karne ke liye
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fn" prefix="fn" %>3. JSP Action Tags <jsp: >
jsp:include — Dynamic include
<jsp:include page="header.jsp" />
<jsp:include page="sidebar.jsp">
<jsp:param name="section" value="home" />
</jsp:include>jsp:forward — Request forward karo
<jsp:forward page="/dashboard.jsp" />jsp:useBean — JavaBean use karo
<jsp:useBean id="student" class="com.example.Student" scope="request" />
<jsp:setProperty name="student" property="name" value="Ram" />
<jsp:getProperty name="student" property="name" />4. JSTL — JSP Standard Tag Library
Core Tags <c: >
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%-- Variable set karo --%>
<c:set var="name" value="Ram" />
<c:set var="age" value="25" />
<%-- if condition --%>
<c:if test="${age >= 18}">
<p>Adult hai</p>
</c:if>
<%-- choose (if-else) --%>
<c:choose>
<c:when test="${age < 13}">Child</c:when>
<c:when test="${age < 18}">Teenager</c:when>
<c:otherwise>Adult</c:otherwise>
</c:choose>
<%-- forEach loop --%>
<c:forEach var="item" items="${studentList}">
<p>${item.name} - ${item.marks}</p>
</c:forEach>
<%-- forEach with index --%>
<c:forEach var="i" begin="1" end="10" step="1">
<p>${i}</p>
</c:forEach>
<%-- forTokens - string split --%>
<c:forTokens var="fruit" items="Apple,Banana,Mango" delims=",">
<li>${fruit}</li>
</c:forTokens>
<%-- redirect --%>
<c:redirect url="/login.jsp" />
<%-- URL encode --%>
<c:url var="link" value="/profile" >
<c:param name="id" value="5" />
</c:url>
<a href="${link}">Profile</a>
<%-- import URL content --%>
<c:import url="http://example.com/data" />
<%-- out - safe output (XSS protection) --%>
<c:out value="${userInput}" escapeXml="true" />Formatting Tags <fmt: >
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%-- Number format --%>
<fmt:formatNumber value="12345.678" type="number" maxFractionDigits="2" />
<fmt:formatNumber value="0.75" type="percent" />
<fmt:formatNumber value="9999" type="currency" currencyCode="INR" />
<%-- Date format --%>
<fmt:formatDate value="${now}" pattern="dd/MM/yyyy HH:mm" />Function Tags <fn: >
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for JSP Tags.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Java topic.
Search Terms
java, java programming, core java, java master course, java notes, master, course, servlets
Related Java Topics