0% found this document useful (0 votes)
2 views

PPT Lecture 3.5

This document covers the JSP include tag and JSP page directive, explaining their syntax, advantages, and differences. The jsp:include action tag allows for dynamic content inclusion at request time, promoting code reusability, while the JSP page directive defines attributes applicable to the entire JSP page. Examples and references for further learning are also provided.

Uploaded by

anuragjangid6373
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

PPT Lecture 3.5

This document covers the JSP include tag and JSP page directive, explaining their syntax, advantages, and differences. The jsp:include action tag allows for dynamic content inclusion at request time, promoting code reusability, while the JSP page directive defines attributes applicable to the entire JSP page. Examples and references for further learning are also provided.

Uploaded by

anuragjangid6373
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

INSTITUTE : UIE

DEPARTMENT : CSE
Bachelor of Engineering (Computer Science
& Engineering)
PROJECT BASED LEARNING IN JAVA WITH LAB
(22CSH-359/22ITH-359)

TOPIC OF PRESENTATION:
JSP include tag, JSP page tag (CO 5)

DISCOVER . LEARN .
EMPOWER
Lecture Objectives

In this lecture, we will


discuss:
•JSP include tag, JSP page tag

2
jsp:include action tag

The jsp:include action tag is used to include the content of another resource
it may be jsp, html or servlet.
The jsp include action tag includes the resource at request time so it is better
for dynamic pages because there might be changes in future.

The jsp:include tag can be used to include static as well as dynamic pages.

Advantage of jsp:include action tag

Code reusability : We can use a page many times such as including header
and footer pages in all pages. So it saves a lot of time.
Difference between jsp include directive and
include action

JSP include directive JSP include action

includes resource at translation time. includes resource at request time.

better for static pages. better for dynamic pages.

includes the original content in the calls the include method.


generated servlet.
Difference between jsp include directive and
include action

Syntax of jsp:include action tag without parameter

<jsp:include page="relativeURL | <%= expression %>" />

Syntax of jsp:include action tag with parameter

<jsp:include page="relativeURL | <%= expression %>">


<jsp:param name="parametername" value="parametervalue | <%=expression%>" />
</jsp:include>
Example of jsp:include action tag without
parameter

In this example, index.jsp file includes the content of the printdate.jsp file.

File: index.jsp

<h2>this is index page</h2>

<jsp:include page="printdate.jsp" />

<h2>end section of index page</h2>

File: printdate.jsp

<% out.print("Today is:"+java.util.Calendar.getInstance().getTime()); %>


JSP page directive
The page directive defines attributes that apply to an entire JSP page.

Syntax of JSP page directive


<%@ page attribute="value" %>

Attributes of JSP page directive


• import
• contentType
• buffer
• language
• isELIgnored
• pageEncoding
• errorPage
• isErrorPage
1)import
The import attribute is used to import class,interface or all the members of
a package.It is similar to import keyword in java class or interface.

Example of import attribute

<html>
<body>

<%@ page import="java.util.Date" %>


Today is: <%= new Date() %>

</body>
</html>
2)contentType
The contentType attribute defines the MIME(Multipurpose Internet Mail
Extension) type of the HTTP response.The default value is
"text/html;charset=ISO-8859-1".
Example of contentType attribute

<html>
<body>

<%@ page contentType=application/msword %>


Today is: <%= new java.util.Date() %>

</body>
</html>
3)extends
The extends attribute defines the parent class that will be inherited by the generated servlet.It
is rarely used.

4)info
This attribute simply sets the information of the JSP page which is retrieved later by using
getServletInfo() method of Servlet interface.
Example of info attribute
<html>
<body>

<%@ page info="composed by Sonoo Jaiswal" %>


Today is: <%= new java.util.Date() %>

</body>
</html>
The web container will create a method getServletInfo() in the resulting servlet.For example:
public String getServletInfo() {
return "composed by Sonoo Jaiswal";
}
5)buffer
The buffer attribute sets the buffer size in kilobytes to handle output generated by
the JSP page.The default size of the buffer is 8Kb.
Example of buffer attribute
<html>
<body>

<%@ page buffer="16kb" %>


Today is: <%= new java.util.Date() %>

</body>
</html>
6)language
The language attribute specifies the scripting language used in the JSP page. The
default value is "java".
7)isELIgnored
We can ignore the Expression Language (EL) in jsp by the isELIgnored attribute. By
default its value is false i.e. Expression Language is enabled by default. We see
Expression Language later.
<%@ page isELIgnored="true" %>//Now EL will be ignored
8)isThreadSafe
Servlet and JSP both are multithreaded.If you want to control this behaviour of JSP
page, you can use isThreadSafe attribute of page directive.The value of
isThreadSafe value is true.If you make it false, the web container will serialize the
multiple requests, i.e. it will wait until the JSP finishes responding to a request
before passing another request to it.If you make the value of isThreadSafe
attribute like:<%@ page isThreadSafe="false" %>
The web container in such a case, will generate the servlet as:
public class SimplePage_jsp extends HttpJspBase
implements SingleThreadModel{
.......
}
9)errorPage
The errorPage attribute is used to define the error page, if exception occurs in the
current page, it will be redirected to the error page.
Example of errorPage attribute
//index.jsp
<html>
<body>

<%@ page errorPage="myerrorpage.jsp" %>

<%= 100/0 %>

</body>
</html>
10)isErrorPage
The isErrorPage attribute is used to declare that the current page is the error page.
Note: The exception object can only be used in the error page.
Example of isErrorPage attribute
//myerrorpage.jsp
<html>
<body>

<%@ page isErrorPage="true" %>

Sorry an exception occured!<br/>


The exception is: <%= exception %>

</body>
</html>
Summary:

In this session, you were able to :


• JSP include tag, JSP page tag
References:
Books:
1. Balaguruswamy, Java.
2. A Primer, E.Balaguruswamy, Programming with Java, Tata McGraw Hill
Companies
3. John P. Flynt Thomson, Java Programming.

Video Lectures :
https://youtu.be/f1Qa7mg2tFE

Reference Links:
https://www.javatpoint.com/jsp-page-directive
https://www.javatpoint.com/jsp-tutorial
https://www.javatpoint.com/jsp-include-action
https://beginnersbook.com/2013/11/jsp-include-action-tag/
https://www.codejava.net/java-ee/jsp/jsp-include-standard-action-examples

You might also like