SlideShare a Scribd company logo
1 of 22
JAVA SERVER PAGE DIRECTIVES
A. D. PATEL INSTITUTE OF TECHNOLOGY
AJ(2160707) : A.Y. 2018-19
GUIDED BY:
PROF. NAYAN MALI
(DEPT OF IT, ADIT)
PREPARED BY:
KUNAL KATHE
E.R.NO.:160010116023
DHRUV SHAH
E.R.NO.:160010116053
CHINTAN SUDANI
E.R.NO.:160010116056
DEPARTMENT OF INFORMATION TECHNOLOGY
A D PATEL INSTITUTE OF TECHNOLOGY (ADIT)
NEW VALLABH VIDYANAGAR, ANAND, GUJARAT
2
Introduction To JSP:
• JSP technology has facilitated the segregation of the work of a Web designer and a Web
developer.
• A Web designer can design and formulate the layout for the Web page by using HTML.
• On the other hand, a Web developer working independently can use java code and other
JSP specific tags to code the business logic.
• The simultaneous construction of the static and dynamic content facilitates development of
quality applications with increased productivity.
• A JSP page , after compilation , generates a servlet and therefore incorporates all servlet
functionalities.
3
• Servlets and JSP thus share common features, such as platform independence , creation of
database-driven Web applications , and server side programming capabilities.
• Servlets tie up files (an HTML file for the static content and a Java file for the dynamic
contents) to independently handle the static presentation logic and the dynamic business
logic.
• Due to this , a change made to any file requires recompilation of the servlet.
• JSP on the other hand allows Java to be embedded directly into an HTML page by using tags.
• The HTML content and the Java content can also be placed in separate files.
• Any changes made to HTML content is automatically compiled and loaded onto the servlet
4
JSP Directives:
• JSP directives provide directions and instructions to the container, telling it how
to handle certain aspects of JSP processing.
• A JSP directive affects the overall structure of the servlet class.
• It usually has the following form:
<%@ directive attribute="value" %>
• The blanks between the @ symbol and the directive name, and between the last attribute
and the closing %>, are optional.
Directive Description
<%@ page ... %> Defines page-dependent attributes, such as scripting language, error
page, and buffering requirements.
<%@ include ... %> Includes a file during the translation phase.
<%@ taglib ... %> Declares a tag library, containing custom actions, used in the page
5
Page directives:
• The page directive is used to provide instructions to the container that pertain to
the current JSP page. You may code page directives anywhere in your JSP page. By
convention, page directives are coded at the top of the JSP page.
• Following is the basic syntax of page directive:
<%@ page attribute="value" %>
• You can write XML equivalent of the above syntax as follows:
<jsp:directive.page attribute="value" />
6
Following is the list of attributes associated with page directive:
Attribute Purpose
buffer Specifies a buffering model for the output stream.
autoFlush Controls the behavior of the servlet output buffer.
contentType Defines the character encoding scheme.
errorPage Defines the URL of another JSP that reports on Java unchecked
runtime exceptions.
isErrorPage Indicates if this JSP page is a URL specified by another JSP
page's errorPage attribute.
extends Specifies a superclass that the generated servlet must extend
import Specifies a list of packages or classes for use in the JSP as the
Java import statement does for Java classes.
info Defines a string that can be accessed with the servlet's
getServletInfo() method.
isThreadSafe Defines the threading model for the generated servlet.
language Defines the programming language used in the JSP page.
session Specifies whether or not the JSP page participates in HTTP
sessions
isELIgnored Specifies whether or not EL expression within the JSP page will
be ignored.
isScriptingEnabled Determines if scripting elements are allowed for use.
7
Include directive:
• The include directive is used to include a file during the translation phase. This
directive tells the container to merge the content of other external files with the
current JSP during the translation phase. You may code include directives
anywhere in your JSP page.
• The general usage form of this directive is as follows:
<%@ include file="relative url" >
• If you just specify a filename with no associated path, the JSP compiler assumes that
the file is in the same directory as your JSP.
• You can write XML equivalent of the above syntax as follows:
<jsp:directive.include file="relative url" />
8
taglib directive:
• The JavaServer Pages API allows you to define custom JSP tags that look like
HTML or XML tags and a tag library is a set of user-defined tags that implement
custom behavior.
• The taglib directive declares that your JSP page uses a set of custom tags,Identifies the
location of the library, and provides a means for identifying the custom tags in your JSP.
• The taglib directive follows the following syntax:
<%@ taglib uri=“http://java.sun.com/jsp/jstl/ex" prefix="prefixOfTag" >
where ex=(core | xml | function | sql)
• Where the uri attribute value resolves to a location the container understands and
the prefix attribute informs a container what bits of markup are custom actions.
9
JSP Tags:
• There are five main tags:
1. Declaration tag
2. Expression tag
3. Directive tag
4. Scriptlet tag
5. Action tag
10
Declaration tag :
• This tag allows the developer to declare variables or methods.
• Before the declaration you must have <%! And at the end of the declaration the
developer must have %>.
• Code placed in this must end in a semicolon(;)
• Declarations do not generate output, so are used with JSP expressions or scriptlets.
• Example:
<%!private int counter = 0 ;
private String getAccount (int accountNo);
%>
11
Expression tag:
• This tag allows the developer to embed any java expression and is short for
out.println().
• A semicolon (;) does not appear at the end of the code inside the tag.
• Example:
<%= new java.util.Date() %>
12
Directive tag:
• A JSP directive gives special information about the jsp page , to the JSP Engine.
• There are three main types of directives:
1. page - processing information for this page
2. Include - files to be included
3. Tag library - tag library to be used in this page
• Directives do not produce any visible output when the page is requested but change the
way the JSP engine processes the page.
• For example , you can make session data unavailable to a page by setting a page
directive (session) to false.
13
Scriptlet tag:
• Between <% and %> tags , any valid Java Code is called a Scriptlet.
• This code can access any variable or bean declared.
• Example:
• <%
String message = “Be in Peace” ;
out.println(message);
%>
14
Action tag:
• Standard Actions are tags that affect the runtime behavior of the JSP and the response
sent back to the user.
• They have to provided by the container irrespective of the usage.
• During compilation into the servlet , the container comes across the this tag and
replaces it with Java code that corresponds to the required predefined task.
• There are three main roles of the action tags:
• Enable the use of the server side Javabeans.
• Transfer control between pages
• Browser independent support for applet
15
Contd…
• Types of the Standard Action :
• <jsp:usebean>
• <jsp:setProperty>
• <jsp:getProperty>
• <jsp:param>
• <jsp:include>
• <jsp:forward>
• <jsp:plugin>
16
Examples Of JSP :
o Action Tag:
• DatePage.jsp
<html>
<body><%= new java.util.Date () %></body>
</html>
• IncludePage.jsp
<html>
<body><h4> Today’s Date is :<jsp:include page=“DatePage.jsp” flush=“true” /> </h4>
<% out.println(“<h4> The ouput of the file DatePage.jsp is shown above </h3>”); %>
</body>
</html>
17
o Taglib Directive :
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head><title>Welcome Page</title></head>
<body>
<c:out value="${'Welcome Dhruv'}" />
</body>
</html>
Output:
18
o Include Directive :
 Login.jsp
<%@include file="include/header.jsp"%>
<%
String USERNAME = (String) request.getSession().getAttribute("USERNAME");
if (USERNAME != null) {
response.sendRedirect("home.jsp");
}
%>
<h2 style="color: lightgray">
<a href="index.jsp">Home</a>
</h2>
<body>
<div class="container">
<form action="AuthenticatorServlet" method="post">
<div class="card">
<center>
<div class="card-header" style="background-color: lightblue">LOGIN
HERE</div></center>
19
<div class="card-body">
<table class="table">
<tr>
<td colspan="2" class="error">
<%
String error = (String) request.getAttribute("ERROR");
if (error != null)
out.println(error);
%>
</td>
</tr>
<tr>
<td>Username</td>
<td><input type="text" name="username" class="form-control"
placeholder="Enter username" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password"
class="form-control" placeholder="Enter password" /></td>
</tr>
20
<tr>
<td></td>
<td><input type="submit" class="btn btn-success"
class="form-control" name="button" value="Submit"></td>
</tr>
</table>
</div>
</div>
</form>
</div>
<%@include file="include/footer.jsp"%>
</body>
</html>
21
 header.jsp
<%@ page language="java" %>
<!DOCTYPE html>
<html>
<head>
<title>ADIT Login Page</title>
<link rel="stylesheet" href="css/bootstrap.min.css" />
</head>
<h1 style="background-color:blue;color:white;text-align:center;">A D Patel Institute Of Technology</h1>
 Footer.jsp
<h3 style="background-color:blue;color:white;text-align:center;">Designed &amp; &copy; Developed By
Dhruv</h3>
</body>
</html>
22

More Related Content

What's hot

What's hot (20)

JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
 
Asp net
Asp netAsp net
Asp net
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Core java
Core javaCore java
Core java
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technology
 
Introduction to JavaScript (1).ppt
Introduction to JavaScript (1).pptIntroduction to JavaScript (1).ppt
Introduction to JavaScript (1).ppt
 
Dhtml ppt (2)
Dhtml ppt (2)Dhtml ppt (2)
Dhtml ppt (2)
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
Jdbc
Jdbc   Jdbc
Jdbc
 
JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - Introduction
 
JDBC ppt
JDBC pptJDBC ppt
JDBC ppt
 
Java servlets and CGI
Java servlets and CGIJava servlets and CGI
Java servlets and CGI
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous Javascript
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
Ajax
AjaxAjax
Ajax
 
History of JavaScript
History of JavaScriptHistory of JavaScript
History of JavaScript
 

Similar to JSP Directives

Servlets and jsp pages best practices
Servlets and jsp pages best practicesServlets and jsp pages best practices
Servlets and jsp pages best practices
ejjavies
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
WebStackAcademy
 

Similar to JSP Directives (20)

Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Jsp
JspJsp
Jsp
 
SCWCD : Java server pages CHAP : 9
SCWCD : Java server pages  CHAP : 9SCWCD : Java server pages  CHAP : 9
SCWCD : Java server pages CHAP : 9
 
Jsp
JspJsp
Jsp
 
JSP.pptx
JSP.pptxJSP.pptx
JSP.pptx
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Jsp in Servlet by Rj
Jsp in Servlet by RjJsp in Servlet by Rj
Jsp in Servlet by Rj
 
Jsp element
Jsp elementJsp element
Jsp element
 
Servlets and jsp pages best practices
Servlets and jsp pages best practicesServlets and jsp pages best practices
Servlets and jsp pages best practices
 
Java Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP BasicJava Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP Basic
 
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
 
Jsp tutorial
Jsp tutorialJsp tutorial
Jsp tutorial
 
Jsp
JspJsp
Jsp
 
JSP Technology I
JSP Technology IJSP Technology I
JSP Technology I
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
 
servlets and jsp
servlets and jspservlets and jsp
servlets and jsp
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
 
Transformation of Java Server Pages: A Modern Approach
Transformation of Java Server Pages: A Modern ApproachTransformation of Java Server Pages: A Modern Approach
Transformation of Java Server Pages: A Modern Approach
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
 
Spatial approximate string search Doc
Spatial approximate string search DocSpatial approximate string search Doc
Spatial approximate string search Doc
 

More from ShahDhruv21

More from ShahDhruv21 (12)

Semantic net in AI
Semantic net in AISemantic net in AI
Semantic net in AI
 
Error Detection & Error Correction Codes
Error Detection & Error Correction CodesError Detection & Error Correction Codes
Error Detection & Error Correction Codes
 
Secure Hash Algorithm (SHA)
Secure Hash Algorithm (SHA)Secure Hash Algorithm (SHA)
Secure Hash Algorithm (SHA)
 
Data Mining in Health Care
Data Mining in Health CareData Mining in Health Care
Data Mining in Health Care
 
Data Compression in Data mining and Business Intelligencs
Data Compression in Data mining and Business Intelligencs Data Compression in Data mining and Business Intelligencs
Data Compression in Data mining and Business Intelligencs
 
MongoDB installation,CRUD operation & JavaScript shell
MongoDB installation,CRUD operation & JavaScript shellMongoDB installation,CRUD operation & JavaScript shell
MongoDB installation,CRUD operation & JavaScript shell
 
2D Transformation
2D Transformation2D Transformation
2D Transformation
 
Interpreter
InterpreterInterpreter
Interpreter
 
Topological Sorting
Topological SortingTopological Sorting
Topological Sorting
 
Pyramid Vector Quantization
Pyramid Vector QuantizationPyramid Vector Quantization
Pyramid Vector Quantization
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 
WaterFall Model & Spiral Mode
WaterFall Model & Spiral ModeWaterFall Model & Spiral Mode
WaterFall Model & Spiral Mode
 

Recently uploaded

Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
Kamal Acharya
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Introduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptxIntroduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptx
hublikarsn
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
pritamlangde
 

Recently uploaded (20)

Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
Worksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptxWorksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptx
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Path loss model, OKUMURA Model, Hata Model
Path loss model, OKUMURA Model, Hata ModelPath loss model, OKUMURA Model, Hata Model
Path loss model, OKUMURA Model, Hata Model
 
Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)
 
Post office management system project ..pdf
Post office management system project ..pdfPost office management system project ..pdf
Post office management system project ..pdf
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Introduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptxIntroduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptx
 
Introduction to Geographic Information Systems
Introduction to Geographic Information SystemsIntroduction to Geographic Information Systems
Introduction to Geographic Information Systems
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
👉 Yavatmal Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Girl S...
👉 Yavatmal Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Girl S...👉 Yavatmal Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Girl S...
👉 Yavatmal Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Girl S...
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
 

JSP Directives

  • 1. JAVA SERVER PAGE DIRECTIVES A. D. PATEL INSTITUTE OF TECHNOLOGY AJ(2160707) : A.Y. 2018-19 GUIDED BY: PROF. NAYAN MALI (DEPT OF IT, ADIT) PREPARED BY: KUNAL KATHE E.R.NO.:160010116023 DHRUV SHAH E.R.NO.:160010116053 CHINTAN SUDANI E.R.NO.:160010116056 DEPARTMENT OF INFORMATION TECHNOLOGY A D PATEL INSTITUTE OF TECHNOLOGY (ADIT) NEW VALLABH VIDYANAGAR, ANAND, GUJARAT
  • 2. 2 Introduction To JSP: • JSP technology has facilitated the segregation of the work of a Web designer and a Web developer. • A Web designer can design and formulate the layout for the Web page by using HTML. • On the other hand, a Web developer working independently can use java code and other JSP specific tags to code the business logic. • The simultaneous construction of the static and dynamic content facilitates development of quality applications with increased productivity. • A JSP page , after compilation , generates a servlet and therefore incorporates all servlet functionalities.
  • 3. 3 • Servlets and JSP thus share common features, such as platform independence , creation of database-driven Web applications , and server side programming capabilities. • Servlets tie up files (an HTML file for the static content and a Java file for the dynamic contents) to independently handle the static presentation logic and the dynamic business logic. • Due to this , a change made to any file requires recompilation of the servlet. • JSP on the other hand allows Java to be embedded directly into an HTML page by using tags. • The HTML content and the Java content can also be placed in separate files. • Any changes made to HTML content is automatically compiled and loaded onto the servlet
  • 4. 4 JSP Directives: • JSP directives provide directions and instructions to the container, telling it how to handle certain aspects of JSP processing. • A JSP directive affects the overall structure of the servlet class. • It usually has the following form: <%@ directive attribute="value" %> • The blanks between the @ symbol and the directive name, and between the last attribute and the closing %>, are optional. Directive Description <%@ page ... %> Defines page-dependent attributes, such as scripting language, error page, and buffering requirements. <%@ include ... %> Includes a file during the translation phase. <%@ taglib ... %> Declares a tag library, containing custom actions, used in the page
  • 5. 5 Page directives: • The page directive is used to provide instructions to the container that pertain to the current JSP page. You may code page directives anywhere in your JSP page. By convention, page directives are coded at the top of the JSP page. • Following is the basic syntax of page directive: <%@ page attribute="value" %> • You can write XML equivalent of the above syntax as follows: <jsp:directive.page attribute="value" />
  • 6. 6 Following is the list of attributes associated with page directive: Attribute Purpose buffer Specifies a buffering model for the output stream. autoFlush Controls the behavior of the servlet output buffer. contentType Defines the character encoding scheme. errorPage Defines the URL of another JSP that reports on Java unchecked runtime exceptions. isErrorPage Indicates if this JSP page is a URL specified by another JSP page's errorPage attribute. extends Specifies a superclass that the generated servlet must extend import Specifies a list of packages or classes for use in the JSP as the Java import statement does for Java classes. info Defines a string that can be accessed with the servlet's getServletInfo() method. isThreadSafe Defines the threading model for the generated servlet. language Defines the programming language used in the JSP page. session Specifies whether or not the JSP page participates in HTTP sessions isELIgnored Specifies whether or not EL expression within the JSP page will be ignored. isScriptingEnabled Determines if scripting elements are allowed for use.
  • 7. 7 Include directive: • The include directive is used to include a file during the translation phase. This directive tells the container to merge the content of other external files with the current JSP during the translation phase. You may code include directives anywhere in your JSP page. • The general usage form of this directive is as follows: <%@ include file="relative url" > • If you just specify a filename with no associated path, the JSP compiler assumes that the file is in the same directory as your JSP. • You can write XML equivalent of the above syntax as follows: <jsp:directive.include file="relative url" />
  • 8. 8 taglib directive: • The JavaServer Pages API allows you to define custom JSP tags that look like HTML or XML tags and a tag library is a set of user-defined tags that implement custom behavior. • The taglib directive declares that your JSP page uses a set of custom tags,Identifies the location of the library, and provides a means for identifying the custom tags in your JSP. • The taglib directive follows the following syntax: <%@ taglib uri=“http://java.sun.com/jsp/jstl/ex" prefix="prefixOfTag" > where ex=(core | xml | function | sql) • Where the uri attribute value resolves to a location the container understands and the prefix attribute informs a container what bits of markup are custom actions.
  • 9. 9 JSP Tags: • There are five main tags: 1. Declaration tag 2. Expression tag 3. Directive tag 4. Scriptlet tag 5. Action tag
  • 10. 10 Declaration tag : • This tag allows the developer to declare variables or methods. • Before the declaration you must have <%! And at the end of the declaration the developer must have %>. • Code placed in this must end in a semicolon(;) • Declarations do not generate output, so are used with JSP expressions or scriptlets. • Example: <%!private int counter = 0 ; private String getAccount (int accountNo); %>
  • 11. 11 Expression tag: • This tag allows the developer to embed any java expression and is short for out.println(). • A semicolon (;) does not appear at the end of the code inside the tag. • Example: <%= new java.util.Date() %>
  • 12. 12 Directive tag: • A JSP directive gives special information about the jsp page , to the JSP Engine. • There are three main types of directives: 1. page - processing information for this page 2. Include - files to be included 3. Tag library - tag library to be used in this page • Directives do not produce any visible output when the page is requested but change the way the JSP engine processes the page. • For example , you can make session data unavailable to a page by setting a page directive (session) to false.
  • 13. 13 Scriptlet tag: • Between <% and %> tags , any valid Java Code is called a Scriptlet. • This code can access any variable or bean declared. • Example: • <% String message = “Be in Peace” ; out.println(message); %>
  • 14. 14 Action tag: • Standard Actions are tags that affect the runtime behavior of the JSP and the response sent back to the user. • They have to provided by the container irrespective of the usage. • During compilation into the servlet , the container comes across the this tag and replaces it with Java code that corresponds to the required predefined task. • There are three main roles of the action tags: • Enable the use of the server side Javabeans. • Transfer control between pages • Browser independent support for applet
  • 15. 15 Contd… • Types of the Standard Action : • <jsp:usebean> • <jsp:setProperty> • <jsp:getProperty> • <jsp:param> • <jsp:include> • <jsp:forward> • <jsp:plugin>
  • 16. 16 Examples Of JSP : o Action Tag: • DatePage.jsp <html> <body><%= new java.util.Date () %></body> </html> • IncludePage.jsp <html> <body><h4> Today’s Date is :<jsp:include page=“DatePage.jsp” flush=“true” /> </h4> <% out.println(“<h4> The ouput of the file DatePage.jsp is shown above </h3>”); %> </body> </html>
  • 17. 17 o Taglib Directive : <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!DOCTYPE html> <html> <head><title>Welcome Page</title></head> <body> <c:out value="${'Welcome Dhruv'}" /> </body> </html> Output:
  • 18. 18 o Include Directive :  Login.jsp <%@include file="include/header.jsp"%> <% String USERNAME = (String) request.getSession().getAttribute("USERNAME"); if (USERNAME != null) { response.sendRedirect("home.jsp"); } %> <h2 style="color: lightgray"> <a href="index.jsp">Home</a> </h2> <body> <div class="container"> <form action="AuthenticatorServlet" method="post"> <div class="card"> <center> <div class="card-header" style="background-color: lightblue">LOGIN HERE</div></center>
  • 19. 19 <div class="card-body"> <table class="table"> <tr> <td colspan="2" class="error"> <% String error = (String) request.getAttribute("ERROR"); if (error != null) out.println(error); %> </td> </tr> <tr> <td>Username</td> <td><input type="text" name="username" class="form-control" placeholder="Enter username" /></td> </tr> <tr> <td>Password</td> <td><input type="password" name="password" class="form-control" placeholder="Enter password" /></td> </tr>
  • 20. 20 <tr> <td></td> <td><input type="submit" class="btn btn-success" class="form-control" name="button" value="Submit"></td> </tr> </table> </div> </div> </form> </div> <%@include file="include/footer.jsp"%> </body> </html>
  • 21. 21  header.jsp <%@ page language="java" %> <!DOCTYPE html> <html> <head> <title>ADIT Login Page</title> <link rel="stylesheet" href="css/bootstrap.min.css" /> </head> <h1 style="background-color:blue;color:white;text-align:center;">A D Patel Institute Of Technology</h1>  Footer.jsp <h3 style="background-color:blue;color:white;text-align:center;">Designed &amp; &copy; Developed By Dhruv</h3> </body> </html>
  • 22. 22