JSP
JSP
JSP is an extension to Servlet because it provides more functionality than servlet such as JSTL
expression language(EL),, etc.
A JSP page consists of HTML tags and JSP tags.
The JSP pages are easier to maintain than servlet because we can separate designing and
development.
It provides some additional features such as Expression Language, Custom tags, etc.,
Advantages of JSP:
1) Extension to servlet:
JSP technology is the extension to servlet technology. We can use all the features of the servlet in JSP. In
addition to, we can use implicit objects, predefined tags, expression language and custom tags in JSP,
that makes JSP development easy.
2) Easy to Maintain:
JSP can easily managed because we can easily separate our business logic with presentation logic. In
servlet technology, we mix our business logic with the presentation logic.
3) Fast Development:
If JSP page is modified, we don’t need to recompile and redeploy the project. The servlet code needs to
be updated and recompiled if we have to change the look and feel of the application.
In JSP, we can use many tags such as action tags, custom tags, etc, that reduces the code. Moreover, we
can use EL, implicit objects, etc.,
1. Declaration tags
2. Expression tags
3. Scriptlet tags
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Hello World</h1>
<h1>Declaration Tags</h1>
<h1>Scriptlet Tags:
<h1>sum=<%=sum %></h1>
</body>
</html>
JSP Directive:
The JSP directives are messages that tells the web container how to translate a JSP page into the
corresponding servlet:
1. Page directive
<%@ page attribute=”value”%>
Arrtibutes of page directives:
import
content type
extends
info
buffer
language
isELIgnored
isThreadSafe
autoFlush
session
pageEncoding
errorPage
isErrorPage
2. Include directive
Current Date:
Index.jsp:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
Header.jsp:
<h1 style="color:black;padding:20px">Header Page</h1>
3. Taglib directive