import JSP page directive with Example

import JSP page directive with Example

"import" is one of the 14 attributes, JSP page directive supports. import JSP is used to import packages in JSP.

Example:

<%@ page import="java.util.List" %> : imports only one interface List

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

In the above three separate import statements, three packages are imported.

JSP import attribute gives a facility of importing multiple import directives in a single line. The above three lines can be substituted with a single line with single import as follows.

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

The packages are separated by commas.

Precaution: There is no semicolon at the end in the import statement.

Following program illustrates import JSP

File Name: PageImport.jsp

ima

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

The above statement is the syntax of import page directive where only one package java.util is imported.

In the above code all the four, import directive, declaration, scriptlet and expression are used.

With all the 9 implicit objects, 4 implicit methods, 3 directives with their attributes and linking with JavaBeans you accept that writing server side code with JSP is very much easier than writing with Servlets. JSP takes less code than Servlets and code productivity increases.

2 thoughts on “import JSP page directive with Example

Leave a Reply

Your email address will not be published. Required fields are marked *