Unit - V Java Server Pages Final
Unit - V Java Server Pages Final
Unit - V Java Server Pages Final
JSP :-
It stands for Java Server Pages.
It is a server side technology.
It is used for creating web application.
It is used to create dynamic web content.
In this JSP tags are used to insert JAVA code into HTML pages.
It is an advanced version of Servlet Technology.
It is a Web based technology helps us to create dynamic and platform independent web
pages.
In this, Java code can be inserted in HTML/ XML pages or both.
JSP is first converted into servlet by JSP container before processing the client’s request.
Demo.jsp
<html>
<head>
<title>Demo JSP</title>
</head>
<%
int demvar=0;%>
<body>
Count is:
<% Out.println(demovar++); %>
<body>
</html>
Demo JSP Page is converted into demo_jsp servlet in the below code.
Output:
Here you can see that in the screenshot theOutput is 1 because demvar is initialized to 0 and
then incremented to 0+1=1
3. Classloading :-
Servlet class that has been loaded from JSP source is now loaded into the container.
4. Instantiation :-
In this step the object i.e. the instance of the class is generated.
The container manages one or more instances of this class in the response to requests and other
events. Typically, a JSP container is built using a servlet container. A JSP container is an
extension of servlet container as both the container support JSP and servlet.
A JSPPage interface which is provided by container provides init() and destroy () methods.
There is an interface HttpJSPPage which serves HTTP requests, and it also contains the service
method.
5. Initialization :-
public void jspInit()
{
//initializing the code
}
_jspinit() method will initiate the servlet instance which was generated from JSP and will be
invoked by the container in this phase.
Once the instance gets created, init method will be invoked immediately after that
It is only called once during a JSP life cycle, the method for initialization is declared as shown
above
6. Request processing :-
void _jspservice(HttpServletRequest request HttpServletResponse
response)
Page 5 Prof. Patil R. M
{
//handling all request and responses
}
_jspservice() method is invoked by the container for all the requests raised by the JSP page
during its life cycle
For this phase, it has to go through all the above phases and then only service method can be
invoked.
It passes request and response objects
This method cannot be overridden
The method is shown above: It is responsible for generating of all HTTP methods i.e. GET,
POST, etc.
7. Destroy:-
public void _jspdestroy()
{
//all clean up code
}
First Program:-
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h2> First Programm </h2>
</body>
</html>
1) JSP Declarations :-
It is often wont to provide all the java declarations like variable declarations, method
definitions. Classes declarations and so on.
A declaration can consist of either method declarations or variables, static constants are a good
example of what to put in a declaration.
The JSP you write turns into a category definition. All the scriptlets you write are placed inside
one method of this class. You can also add variable and method declarations to the present
class.
You can then use these variables and methods from your scriptlets and expressions. We can use
declarations to declare one or more variables and methods at the category level of the compiled
servlet.
The fact that they are declared at a class level rather than in the body of the page is significant.
The class members (variables and methods) can then be employed by Java code within the
remainder of the page.
When you write a declaration during a JSP page, remember these rules:
1. Must end the declaration with a semicolon.
2. <% int i=0;%>
3. We can use variables or methods that are declared in packages imported by the page directive,
without declaring them in a declaration element.
4. We can declare any number of variables or methods within one declaration element, as long as
you end each declaration with a semicolon. The declaration must be valid in the Java
programming language.
If we offer any java declarations by using-declaration scripting element then that each one java
declarations are going to be available to the translated servlet as class-level declarations.
Output
The code placed in the declaration tag goes to JES class outside of the _jspService(_,_) method.
Variables declared in the declaration tag becomes global variables in JES class. Variables declared in
the declaration tag become a global variable in JES class. Implicit objects are not visible in the
declaration tag because they are the local variable of _jspService(_,_) method, and the code placed in
the declaration tag goes to the outside _jspService(_,_) method. We can also use declaration tag to
place jspInit() and jspDestroy() method definition in our JSP program.
Note: The XML equivalent of <%! Code %> is:
<jsp:declaration>
Code
</jsp:declaration>
2) JSP Scriptlets:-
This scripting element is often wont to provide a block of java code. It can contain any number of
language statements, variable or method declarations, or expressions that are valid within the page
scripting language. Within a scriptlet, you can do the following:
1. On the JSP page declare variables or methods to use later.
2. Write valid expressions in the page scripting language.
3. Use any of the implicit objects or any object declared with the element.
4. On the JSP page, write any other statement valid in the scripting language used.
5. All text, HTML tags, or JSP elements you write must be outside the scriptlet.
Output
3) JSP Expressions:-
This is scripting element are often wont to evaluate the only java expression and display that
expression resultant value onto the client browser. The expression element contains a Java expression
that returns a worth. This value is then written to the HTML page. The Expression tag can contain any
expression that’s valid consistent with the Java Language Specification. This includes variables,
method calls then return values, or any object that contains a toString() method. It evaluates the given
expression displays generated results onto browser windows. Anything that returns a result is called an
expression.
Syntax: <%=Java Expression%>
If we provide any java expression in expression scripting elements then that expression will be
available to translated servlet inside _JspService(_,_) method as a parameter to out.write() method. If
the expression tag is used perfectly then there is no need of using out.println() on the JSP page. The
code placed in the expression tag goes to the _JspService(_,_) method of JES class, so we can use
implicit objects in expression tags. We can use the expression tag for instantiation and display data of
the object. We can use the expression tag to call both user-defined and pre-defined methods, which
return results. Here, the java expression is evaluated and then converted to String and inserted in the
page. This evaluation is performed at run-time (when the page is requested), and thus has full access to
the information about the request.
Output
Note: XML authors can use an alternative syntax for JSP expressions:
<jsp:expression>
Java Expression
</jsp:expression>
The XML elements, unlike HTML ones, are case sensitive. So be sure to use lowercase
<!DOCTYPE html>
<html>
<head>
<title>request implicit object</title>
</head>
<body bgcolor="pink">
<form action="welcome.jsp">
<input type="text" name="uname"> <input type="submit"
value="GO"><br />
</form>
</body>
</html>
welcome.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
Output
Run your code to get the following output.
!DOCTYPE html>
<html>
<head>
<title>implicit object</title>
</head>
<body bgcolor="pink">
<form action="welcome.jsp">
<input type="text" name="uname"> <input type="submit"
value="GO"><br />
welcome.jsp
Output
Run your code to get the following output:
<!DOCTYPE html>
<html>
<head>
<title>implicit object</title>
</head>
<body bgcolor="pink">
<form action="welcome.jsp">
<input type="text" name="uname"> <input type="submit"
value="GO"><br />
welcome.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body bgcolor="pink">
<%
String name = request.getParameter("uname");
out.print("Welcome " + name);
session.setAttribute("user", name);
%>
<a href="second.jsp">second jsp page</a>
</body>
</html>
second.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body bgcolor="pink">
<%
String name = (String) session.getAttribute("user");
out.print("Hello " + name);
%>
</body>
Page 21 Prof. Patil R. M
</html>
Output
<!DOCTYPE html>
Output
Run your code to get the following output:
index.jsp
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<servlet>
<servlet-name>WelcomeServlet</servlet-name>
<jsp-file>/index.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>WelcomeServlet</servlet-name>
<url-pattern>/index</url-pattern>
</servlet-mapping>
</web-app>
index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body bgcolor="pink">
<%
out.print("Today is:" + java.util.Calendar.getInstance().getTime());
%>
</body>
</html>
Output
Example
public final view_jsp extends HttpBase…{
public void _jspService(request, response)…{
Object page=this;
}
}
<!DOCTYPE html>
division.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body bgcolor="pink">
<%@ page errorPage="exception.jsp"%>
<%
String num1 = request.getParameter("firstnum");
String num2 = request.getParameter("secondnum");
int v1 = Integer.parseInt(num1);
int v2 = Integer.parseInt(num2);
int res = v1 / v2;
out.print("Output is: " + res);
%>
</body>
</html>
exception.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
Page 28 Prof. Patil R. M
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body bgcolor="pink">
<%@ page isErrorPage="true"%>
Got this Exception:
<%=exception%>
Please correct the input data.
</body>
</html>
Output
HTML
<html>
<head>
<body>
<form action="a.jsp">
Number1:<input type="text" name="first" >
Number2:<input type="text" name="second" >
<input type="submit" value="divide">
</form>
</body>
</html>
A.jsp
Java
Page 30 Prof. Patil R. M
// JSP code to divide two numbers
<% @page errorPage = "error.jsp" %> < %
String num1 = request.getParameter("first");
String num2 = request.getParameter("second");
// extracting numbers from request
int x = Integer.parseInt(num1);
int y = Integer.parseInt(num2);
int z = x / y; // dividing the numbers
out.print("division of numbers is: " + z); // result
%>
error.jsp
Java
// JSP code for error page, which displays the exception
<% @page isErrorPage = "true" %>
Output:
index.html
error.jsp
Advantage of JSTL
1. Fast Developement JSTL provides many tags that simplifies the JSP.
2. Code Reusability We can use the JSTL tags in various pages.
3. No need to use scriptlet tag It avoids the use of scriptlet tag.
JSTL Tags :-
1) Core Tags
The core group of tags are the most commonly used JSTL tags. Following is the syntax to include the
JSTL Core library in your JSP −
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
Following table lists out the core JSTL Tags −
1 <c:out>
<c:set >
2
Sets the result of an expression evaluation in a 'scope'
<c:remove >
3
Removes a scoped variable (from a particular scope, if specified).
<c:catch>
4
Catches any Throwable that occurs in its body and optionally exposes it.
<c:if>
5
Simple conditional tag which evalutes its body if the supplied condition is true.
<c:choose>
6 Simple conditional tag that establishes a context for mutually exclusive conditional
operations, marked by <when> and <otherwise>.
<c:when>
7
Subtag of <choose> that includes its body if its condition evalutes to 'true'.
<c:otherwise >
8
Subtag of <choose> that follows the <when> tags and runs only if all of the prior
conditions evaluated to 'false'.
<c:import>
9 Retrieves an absolute or relative URL and exposes its contents to either the page, a
String in 'var', or a Reader in 'varReader'.
<c:forEach >
10
The basic iteration tag, accepting many different collection types and supporting
subsetting and other functionality .
<c:forTokens>
11
Iterates over tokens, separated by the supplied delimeters.
<c:redirect >
13
Redirects to a new URL.
<c:url>
14
Creates a URL with optional query parameters
2) Formatting Tags:-
The JSTL formatting tags are used to format and display text, the date, the time, and numbers for
internationalized Websites. Following is the syntax to include Formatting library in your JSP −
<%@ taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt" %>
Following table lists out the Formatting JSTL Tags −
<fmt:formatNumber>
1
To render numerical value with specific precision or format.
<fmt:parseNumber>
2
Parses the string representation of a number, currency, or percentage.
<fmt:formatDate>
3
Formats a date and/or time using the supplied styles and pattern.
<fmt:parseDate>
4
Parses the string representation of a date and/or time
<fmt:bundle>
5
Loads a resource bundle to be used by its tag body.
6 <fmt:setLocale>
<fmt:setBundle>
7 Loads a resource bundle and stores it in the named scoped variable or the bundle
configuration variable.
<fmt:timeZone>
8
Specifies the time zone for any time formatting or parsing actions nested in its
body.
<fmt:setTimeZone>
9
Stores the given time zone in the time zone configuration variable
<fmt:message>
10
Displays an internationalized message.
<fmt:requestEncoding>
11
Sets the request character encoding
3) SQL Tags:-
The JSTL SQL tag library provides tags for interacting with relational databases (RDBMSs) such
as Oracle, mySQL, or Microsoft SQL Server.
Following is the syntax to include JSTL SQL library in your JSP −
<%@ taglib prefix = "sql" uri = "http://java.sun.com/jsp/jstl/sql" %>
Following table lists out the SQL JSTL Tags −
<sql:setDataSource>
1
Creates a simple DataSource suitable only for prototyping
<sql:query>
2
Executes the SQL query defined in its body or through the sql attribute.
<sql:param>
4
Sets a parameter in an SQL statement to the specified value.
<sql:dateParam>
5
Sets a parameter in an SQL statement to the specified java.util.Date value.
<sql:transaction >
6 Provides nested database action elements with a shared Connection, set up to
execute all statements as one transaction.
4) XML tags:-
The JSTL XML tags provide a JSP-centric way of creating and manipulating the XML documents.
Following is the syntax to include the JSTL XML library in your JSP.
The JSTL XML tag library has custom tags for interacting with the XML data. This includes parsing
the XML, transforming the XML data, and the flow control based on the XPath expressions.
<%@ taglib prefix = "x"
uri = "http://java.sun.com/jsp/jstl/xml" %>
Before you proceed with the examples, you will need to copy the following two XML and XPath
related libraries into your <Tomcat Installation Directory>\lib −
XercesImpl.jar − Download it from https://www.apache.org/dist/xerces/j/
xalan.jar − Download it from https://xml.apache.org/xalan-j/index.html
Following is the list of XML JSTL Tags −
<x:out>
1
Like <%= ... >, but for XPath expressions.
<x:parse>
2
Used to parse the XML data specified either via an attribute or in the tag body.
<x:if >
4
Evaluates a test XPath expression and if it is true, it processes its body. If the test
condition is false, the body is ignored.
<x:forEach>
5
To loop over nodes in an XML document.
<x:choose>
6
Simple conditional tag that establishes a context for mutually exclusive conditional
operations, marked by <when> and <otherwise> tags.
<x:when >
7
Subtag of <choose> that includes its body if its expression evalutes to 'true'.
<x:otherwise >
8
Subtag of <choose> that follows the <when> tags and runs only if all of the prior
conditions evaluates to 'false'.
<x:transform >
9
Applies an XSL transformation on a XML document
<x:param >
10
Used along with the transform tag to set a parameter in the XSLT stylesheet
5) JSTL Functions:-
JSTL includes a number of standard functions, most of which are common string manipulation
functions. Following is the syntax to include JSTL Functions library in your JSP −
<%@ taglib prefix = "fn"
uri = "http://java.sun.com/jsp/jstl/functions" %>
Following table lists out the various JSTL Functions −
fn:containsIgnoreCase()
2
Tests if an input string contains the specified substring in a case insensitive way.
fn:endsWith()
3
Tests if an input string ends with the specified suffix.
fn:escapeXml()
4
Escapes characters that can be interpreted as XML markup.
fn:indexOf()
5
Returns the index withing a string of the first occurrence of a specified substring.
fn:join()
6
Joins all elements of an array into a string.
fn:length()
7
Returns the number of items in a collection, or the number of characters in a string.
fn:replace()
8
Returns a string resulting from replacing in an input string all occurrences with a
given string.
fn:split()
9
Splits a string into an array of substrings.
fn:startsWith()
10
Tests if an input string starts with the specified prefix.
fn:substring()
11
Returns a subset of a string.
fn:substringBefore()
13
Returns a subset of a string before a specific substring.
fn:toLowerCase()
14
Converts all of the characters of a string to lower case.
fn:toUpperCase()
15
Converts all of the characters of a string to upper case.
fn:trim()
16
Removes white spaces from both ends of a string.
What is JSTL?
JSTL stands for Java server pages standard tag library.
It is a collection of custom JSP tag libraries that provide common web development
functionality.
JSTL is a standard tag library of the JSP.
JSTL (JSP Standard Tag Library) is a collection of custom tags that provide common
functionalities like flow control, database operations, etc.
JSTL tags can be embedded in Java Server Pages just like other HTML tags.
It is convenient for front-end developers to work with HTML-like tags for including logic in
webpages rather than writing Java code in scripts.
To use JSTL tags, the following dependencies must be included in pom.xml in a maven project:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
The following tags are included in the JSTL Core tag library:
catch
choose
if
import
forEach
forTokens
out
otherwise
param
redirect
remove
set
url
when
1) c:set
It is used to set a value to a variable that can be used within the specified scope in a JSP.
Tag handler class: org.apache.taglibs.standard.tag.rt.core.SetTag
Body content: jsp
Attributes:
var: It is used to provide the name of the variable.
value: It is used to provide the value for the variable. It can contain any expression.
scope: It is used to set the scope of the variable.
target: It is used to provide the target object whose property is to be set.
property: It is used to specify the name of the property to be set for the target object.
Example:
set.jsp
<%@ page language="java" contentType="text/html; charset=ISO -8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-
1">
<title>Set Tag</title>
</head>
Output:
My Name is John
2) c:remove
removes the specified variable.
Tag handler class: org.apache.taglibs.standard.tag.common.core.RemoveTag
Body-content: empty
Attributes:
var: It is used to specify the variable to be removed.
Example:
remove.jsp
Output:
My Name is John
My Name is
In the above example, the variable name is removed, therefore, the second <c:out>
doesn’t display the name.
3) c:out
It is used to display the content on the web page similar to the expression tag (<%=
%).
Tag handler class: org.apache.taglibs.standard.tag.rt.core.OutTag.
Body content: jsp
Attributes:
value: It is used to provide the value to be displayed.
default: It is used to provide the default value, in case, the value
provided is null.
Example:
out.jsp
page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-
1">
<title>Out Tag</title>
</head>
<body>
<h1>
<c:out value="We are learning JSTL Core Tags"/>
Output:
We are learning JSTL Core Tags
4) c:forEach
used to iterate over a collection or an array.
Tag handler class: org.apache.taglibs.standard.tag.rt.core.ForEachTag
Body content: jsp
Attributes:
items: It is used to provide a collection of objects to iterate over.
begin: It is used to specify the beginning of the iteration.
end: It is used to specify the end of the iteration.
step: It is used to provide the steps to be taken between two
consecutive iterations.
var: It is used to provide a variable for a current item of the iteration.
Example:
forEach.jsp
<%@ page language="java" contentType="text/html; charset=ISO -8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-
1">
<title>ForEach Tag</title>
</head>
<body>
<h1>
<c:forEach var="i" begin="1" end="10" step="2">
<c:out value="${i}"/>
</c:forEach>
<br>
<%
int[] marks={10,12,15,14,9};
session.setAttribute("marks",marks);
%>
Output:
1 3 5 7 9
10 12 15 14 9
5) c:import
It is used to include the contents from relative or absolute urls within or outside the
server.
Tag handler class: org.apache.taglibs.standard.tag.rt.core.ImportTag
Body content: jsp
Attributes:
url: It is used to specify the url of the resource to be imported.
var: It is used to provide the var in which contents of the imported
resource are to be stored.
scope: It is used to specify the scope.
Example:
import.jsp
<%@ page language="java" contentType="text/html; charset=ISO -8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-
1">
<title>Import Tag</title>
</head>
<body>
<c:import var="content" url="http://www.google.com"/>
<c:out value="${content}"/>
</body>
</html>
Output:
Welcome John!
7) c:catch
It is used to catch any exception of type Throwable that occurs in the body.
Tag handler class: org.apache.taglibs.standard.tag.common.core.CatchTag
Body-content: jsp
Attributes:
var: used to store the exception thrown by body-content.
Example:
catch.jsp
8) c:if
It is used to include the conditional statement in the java server pages. Body content
is evaluated only when the condition evaluates to true.
Tag handler class: org.apache.taglibs.standard.tag.rt.core.IfTag
Body-content: jsp
Attributes:
test: used to provide the testing condition.
Example:
if.jsp
<%@ page language="java" contentType="text/html; charset=ISO -8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-
1">
<title>If Tag</title>
</head>
<body>
<h1>
<c:set var="marks" value="80"/>
<c:if test="${marks>33 }">
Qualified!!
</c:if>
</h1>
</h1>
</body>
</html>
Output:
A Grade
11) c:url
It is used to create a formatted url along with parameters using a nested <c:param>
tag.
Tag handler class: org.apache.taglibs.standard.tag.rt.core.UrlTag
Body content: jsp
Attributes:
var: It is used to provide the variable that holds the url.
scope: It is used to set the scope.
value: It is used to provide the url to be formatted.
Example:
<%@ page language="java" contentType="text/html; charset=ISO -8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-
1">
<title>Url Tag</title>
</head>
<body>
<h1>
<a href = "
<c:url value = "/jsp/welcome.jsp"/>
">Click here</a>
</h1>
</body>
</html>
Page 49 Prof. Patil R. M
Output:
Click here
Advantages of JSTL
Below are the advantages of JSTL:
1. Standard Tag: It provides a rich layer of the portable functionality of JSP pages. It’s easy for a
developer to understand the code.
2. Code Neat and Clean: As scriplets confuse developer, the usage of JSTL makes the code neat
and clean.
3. Automatic Java beans Interospection Support: It has an advantage of JSTL over JSP
scriptlets. JSTL Expression language handles JavaBean code very easily. We don’t need to
downcast the objects, which has been retrieved as scoped attributes. Using JSP scriptlets code
will be complicated, and JSTL has simplified that purpose.
4. Easier for humans to read: JSTL is based on XML, which is very similar to HTML. Hence, it
is easy for the developers to understand.
5. Easier for computers to understand: Tools such as Dreamweaver and front page are
generating more and more HTML code. HTML tools do a great job of formatting HTML code.
The HTML code is mixed with the scriplet code. As JSTL is expressed as XML compliant tags,
it is easy for HTML generation to parse the JSTL code within the document.