< Prev
Next >



JSP include Directive





include Directive


The JSP include directive allows you to include the content of a web page in the current web page. The location where you insert the include directive in a web page is very important because it is at that specific location where the content of a web page is added in the current web page.




Syntax of include Directive


<%@ include file = " relative URL of the file " %>





include Directive Example


We have created a JSP web page that displays the current day, date and time, as shown below.

Date.jsp
<html>

<head>
<title>Display Date</title>
</head>


<body>

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

Current Date and Time : <%= new Date() %>

</body>

</html>



Next we have created a web page that uses include directive to include the contents of a web page Date.jsp(which displays the current date and time) at a particular location of the current web page.



IncludeExample.jsp
<html>

<head>
<title>Display Date</title>
</head>


<body>

Including the content of another page using include directive :
<%@ include file="Date.jsp" %> </body> </html>



executing this JSP page includes the content of Date.jsp and displays it the user.






Another example of include directive


In this example, we are going to include a webpage with a form, using include directive.

login1.jsp
<html>

<head>
<title>Login Form</title>
</head>


<body>


<form action="login.jsp" method="post">
    <b>Username</b>
    <input type="text" name="username">
    <b>Password</b>
    <input type="password" name="password">
    <button type="submit">Login</button>
</form>

</body>

</html>




IncludingExample2.jsp
<html>

<head>
<title>Using include directive</title>
</head>


<body>


Including the content of another page using include directive :
<%@ include file="login1.jsp" %> </body> </html>



executing IncludingExample2.jsp webpage displays the including contents of login1.jsp to the user.





Please share this article -

Facebook Google Pinterest Reddit Tumblr Twitter



< Prev
Next >
< JSP isErrorPage & errorPage Attribute
JSP taglib Directive >

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page

Notifications



Please check our latest addition

PYTHON