Advertisement



< Prev
Next >



JSP Directives





As it is evident from its name, JSP directives are a set of directions or instructions that allow you set how a JSP page is going to be processed and displayed. For example, by using JSP directives you can-



Three types of directives in JSP are:






The page directive


The page directive allows you to configure the entire JSP page by importing the required classes, setting the content type, setting the error page, etc. Page directives has a few important attributes which you may use to configure your JSP web page such as-
Note: In this tutotial, we are going to discuss the import attribute of the page directive.



The import attribute


The import attribute is used to import a Java package that could be required by the java code embedded in a JSP web page. For example, we may import java.util package in order to print the current day and time in a JSP web page. Let's see how it is done.



import3.jsp
<!–– Example of import attribute of page directive of JSP -->

<html>

<head>
	<title>JSP import attribute</title>
</head>


<body>

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


<% Date d =  new Date(); %>
The current date and time : <%= d %>


<% DateFormat df = DateFormat.getInstance(); %>

<br/>

The formatted date and time : <%= df.format(d) %>

</body>

</html>

We have imported two individual classes, i.e. Date and DateFormat in a JSP web page. We have displayed the current day, date and time in its simple form by using the Date class, and have also displayed the current date and time in its formatted form by using the DateFormat class, as shown below.






Note :




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

<html>

<head>
<title>JSP import attribute</title>
</head>


<body>

The current date and time <%= new Date() %>

</body>

</html>


Executing the above mentioned import4.jsp file gives the same result as import.jsp.



Please share this article -




< Prev
Next >
< JSP Scripting Elements
JSP contentType Attribute >



Advertisement

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement



Notifications



Please check our latest addition

C#, PYTHON and DJANGO


Advertisement