Top 20 JSP Standard Tag Library (JSTL) Interview Questions
Q1. Explain Jstl Core Tags?
JSTL Core tags provide aid for iteration, conditional common sense, catch exception, url, ahead or redirect response and so forth. To use JSTL center tags, we need to encompass it inside the JSP web page like below.
<%@ taglib uri="http://java.Sun.Com/jsp/jstl/core" prefix="c" %>
<pre class="prettyprint">
Q2. What Are The Advantage Of Jstl?
Fast Developement JSTL offers many tags that simplifies the JSP.
Code Reusability We can use the JSTL tags in numerous pages.
No want to use scriptlet tag It avoids the usage of scriptlet tag.
Q3. Explain Formatting Tags?
Formatting tags: JSTL Formatting tags are supplied for formatting of Numbers, Dates and i18n guide through locales and resource bundles. We can include those jstl tags in JSP with below syntax:
<pre class="prettyprint">
<%@ taglib uri="http://java.Sun.Com/jsp/jstl/fmt" prefix="fmt" %>
Q4. List Some Jstl Core Tags?
JSTL Core Tags :
<c:out> : To write some thing in JSP web page, we are able to use EL also with this tag.
<c:import> : Same as <jsp:include> or encompass directive.
<c:redirect> : redirect request to every other resource.
<c:set> : To set the variable fee in given scope.
<c:remove> : To remove the variable from given scope.
<c:catch> : To trap the exception and wrap it into an item.
<c:if> : Simple conditional good judgment, used with EL and we will use it to manner the exception from <c:catch>.
<c:choose> : Simple conditional tag that establishes a context for mutually distinct conditional operations, marked by <c:when> and <c:otherwise>.
<c:when> : Subtag of <c:choose> that consists of its frame if its situation evalutes to 'genuine'.
<c:otherwise> : Subtag of <c:choose> that includes its frame if its circumstance evalutes to 'false'.
Q5. What Is A Tag Library?
The JavaServer Pages Standard Tag Library (JSTL) is a component of the Java EE Web utility development platform. It extends the JSP specification by using adding a tag library of JSP tags for commonplace obligations, along with XML records processing, conditional execution, database access, loops and internationalization.
Q6. Explain Jstl Foreach Tag With An Example?
JSTL forEach tag: This tag affords a mechanism for iteration inside a JSP page. JSTL forEach tag works further to enhanced for loop of Java Technology. You can use this tag to iterate over an existing series of gadgets. For Example :
<%@ taglib uri="http://java.Sun.Com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>Tag Example</title>
</head>
<body>
<c:forEach var="message" items="$errorMsgs" >
<li>$message</li>
</c:forEach>
</body>
</html>
Here the characteristic items has its fee as an EL expression which is a collection of errors messages. Each item inside the generation can be saved in a variable called message to be able to be available inside the body of the forEach tag.
Q7. Explain Xml Tags?
JSTL XML Tags: JSTL XML tags are used to work with XML documents which includes parsing XML, trforming XML statistics and XPath expressions assessment. Syntax to consist of JSTL XML tags in JSP page is:
<%@ taglib uri="http://java.Sun.Com/jsp/jstl/xml" prefix="x" %>
Q8. Explain Sql Tags?
SQL tags : JSTL SQL Tags: JSTL SQL Tags offer assist for interplay with relational databases inclusive of Oracle, MySql and so forth. Using JSTL SQL tags we are able to run database queries, we consist of those JSTL tags in JSP with beneath syntax:
<%@ taglib uri="http://java.Sun.Com/jsp/jstl/sql" prefix="sql" %>
Q9. Explain Jstl Choose, When, Otherwise Tag With An Example?
JSTL choose, when, in any other case tag: These are conditional tags used to enforce conditional operations. If the test situation of the when tag evaluates to actual, then the content material inside when tag is evaluated, otherwise the content within the otherwise tag is evaluated.
We can also put into effect if-else-if assemble by means of using a couple of when tag. The while tags are at the same time distinct, that me the primary when tag which evaluates to genuine is evaluated after which, the control exits the pick block. If not one of the while situation evaluates to true, then otherwise situation is evaluated. For Example
<%@ taglib uri="http://java.Sun.Com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>Tag Example</title>
</head>
<body>
<c:forEach var="tutorial" items="$MyTutorialMap" begin="0" end="5" varStatus="status">
<c:choose>
<c:when test="$status.Count %2 == 0 ">
<p> Divisible by means of 2 : $educational.Key </p>
<br/>
</c:when>
<c:when test="$status.Count %5 == 0 ">
<p > Divisible with the aid of five : $academic.Key </p>
<br/>
</c:when>
<c:otherwise>
<p> Neither divisible by 2 nor 5 : $educational.Key </p><br/>
</c:otherwise>
</c:choose>
</c:forEach>
</body>
</html>
Q10. What Is A Taglib?
JSP - The taglib Directive. Advertisements. The JavaServer Pages API lets in you to outline custom JSP tags that look like HTML or XML tags and a tag library is a set of user-defined tags that enforce custom behavior. ... When you operate a custom tag, it's miles generally of the form <prefix:tagname>.
Q11. Explain Jstl Catch Tag With An Example?
JSTL seize tag: The JSTL catch tag is used to deal with exception and would not forward the web page to the mistake web page. For Example :
<%@ taglib uri="http://java.Sun.Com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>Tag Example</title>
</head>
<body>
<c:catch>
<% int a = 0;
int b = 10;
int c = b/a;
%>
</c:catch>
</body>
</html>
Q12. List Some Formatting Tags?
Formatting Tags Descriptions :
fmt:parseNumber : It is used to Parses the string representation of a foreign money, percentage or range.
Fmt:timeZone : It specifies a parsing movement nested in its body or the time quarter for any time formatting.
Fmt:formatNumber : It is used to layout the numerical fee with specific format or precision.
Fmt:parseDate : It parses the string illustration of a time and date.
Fmt:package : It is used for growing the ResourceBundle gadgets with a view to be used by their tag frame.
Fmt:setTimeZone : It stores the time area inside a time quarter configuration variable.
Fmt:setBundle : It loads the resource bundle and shops it in a package deal configuration variable or the named scoped variable.
Fmt:message : It display an internationalized message.
Fmt:formatDate : It codecs the time and/or date the usage of the supplied sample and patterns.
Q13. Explain Jstl If Tag With An Example?
The if tag is a conditional tag used to evaluate conditional expressions. When a frame is provided with if tag, the frame is evaluated handiest when the expression is proper. For Example :
<%@ taglib uri="http://java.Sun.Com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>Tag Example</title>
</head>
<body>
<c:if test="$param.Name == 'studytonight'">
<p>Welcome to $param.Name </p>
</c:if>
</body>
</html>
Q14. Explain Function Tags?
Function tags: JSTL Functions Tags: JSTL tags offer a number of capabilities that we will use to perform common operation, maximum of them are for String manipulation inclusive of String Concatenation, Split String and so forth. Syntax to encompass JSTL functions in JSP page is:
<%@ taglib uri="http://java.Sun.Com/jsp/jstl/functions" prefix="fn" %>
Q15. Explain Jstl Out Tag?
JSTL out tag: The out tag is used to assess an expression and write the result to JspWriter. For Example :
<%@ taglib uri="http://java.Sun.Com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>Tag Example</title>
</head>
<body>
<c:out value="$param.Name" default="StudyTonight" />
</body>
</html>
The cost attribute specifies the expression to be written to the JspWriter. The default characteristic specifies the fee to be written if the expression evaluates null.
Q16. What Is Jstl?
The JavaServer Pages Standard Tag Library (JSTL) is a set of beneficial JSP tags which encapsulates middle capability not unusual to many JSP programs. JSTL has guide for not unusual, structural duties together with iteration and conditionals, tags for manipulating XML documents, internationalization tags, and SQL tags.
Q17. List Some Function Tags?
JSTL Function Tags List :
fn:consists of() : It is used to test if an input string containing the required substring in a program.
Fn:containsIgnoreCase() : It is used to check if an input string carries the desired substring as a case insensitive way.
Fn:endsWith() : It is used to check if an enter string ends with the required suffix.
Fn:escapeXml() : It escapes the characters that could be interpreted as XML markup.
Fn:indexOf() : It returns an index inside a string of first incidence of a designated substring.
Fn:trim() : It removes the clean spaces from both the ends of a string.
Fn:startsWith() : It is used for checking whether or not the given string is commenced with a specific string cost.
Fn:split() : It splits the string into an array of substrings.
Fn:toLowerCase() : It converts all the characters of a string to decrease case.
Fn:toUpperCase() : It converts all the characters of a string to higher case.
Q18. How Many Tags Are Provided By Jstl? What Are They?
There JSTL especially presents 5 varieties of tags:
Core tags.
Function tags.
Formatting tags.
XML tags.
SQL tags.
Q19. List Some Jstl Sql Tags?
Square:setDataSource: It is used for growing a easy information supply appropriate most effective for prototyping.
Sq.:query: It is used for executing the SQL query described in its square characteristic or the frame.
Square:update: It is used for executing the SQL replace defined in its sq. Characteristic or within the tag body.
Square:param: It is used for units the parameter in an SQL announcement to the specified fee.
Square:dateParam: It is used for sets the parameter in an SQL statement to a distinct java.Util.Date cost.
Square:traction: It is used to provide the nested database action with a commonplace connection.
Q20. What Is Implicit Object?
JSP Implicit Objects are the Java objects that the JSP Container makes available to builders in each page and developer can name them directly with out being explicitly declared. JSP Implicit Objects also are known as pre-defined variables.

