SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Language
jaimefrozr
 

Was ist angesagt? (20)

Servlets
ServletsServlets
Servlets
 
JDBC ppt
JDBC pptJDBC ppt
JDBC ppt
 
Struts framework
Struts frameworkStruts framework
Struts framework
 
Jdbc Ppt
Jdbc PptJdbc Ppt
Jdbc Ppt
 
Presentation of bootstrap
Presentation of bootstrapPresentation of bootstrap
Presentation of bootstrap
 
Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Language
 
Introduction to java beans
Introduction to java beansIntroduction to java beans
Introduction to java beans
 
Session bean
Session beanSession bean
Session bean
 
Servlets
ServletsServlets
Servlets
 
Multithreading in-java
Multithreading in-javaMultithreading in-java
Multithreading in-java
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
 
Java Programming for Designers
Java Programming for DesignersJava Programming for Designers
Java Programming for Designers
 
Lecture 3: Servlets - Session Management
Lecture 3:  Servlets - Session ManagementLecture 3:  Servlets - Session Management
Lecture 3: Servlets - Session Management
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
JDBC
JDBCJDBC
JDBC
 
Php string function
Php string function Php string function
Php string function
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 

Ähnlich wie 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
 

Ähnlich wie 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
 
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
 
Spatial approximate string search Doc
Spatial approximate string search DocSpatial approximate string search Doc
Spatial approximate string search Doc
 
Jsp and jstl
Jsp and jstlJsp and jstl
Jsp and jstl
 
Java server pages
Java server pagesJava server pages
Java server pages
 

Mehr von ShahDhruv21

Mehr von 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
 

Kürzlich hochgeladen

VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
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
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 

Kürzlich hochgeladen (20)

Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
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
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 

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