Share on Google+Share on Google+

"import" Attribute of page directive

Advertisement
In this Section , we will discuss about the "import" attribute of a JSP & its use in JSP page.

"import" Attribute of page directive

In this Section , we will discuss about the "import" attribute of a JSP & its use in JSP page. A directive element in a JSP page provides global information about a particular JSP page. Page directive attributes that notify the Web container about the general settings of a JSP page. The syntax of the page directive is  : 

  <%@    page attribute_list    %>

The "import" attribute imports the list of packages, classes, or interfaces into the generated servlet. It is similar to java import statement. The syntax of this page directive is :

<%@page import="package_name . class_name" %> 

The default value of this attribute is java.lang.* , javax.servlet.* , javax.servlet.jsp.*  and  javax.servlet.http.*.

code of java file

package foo;

public class gocha{

public String show(){

return "JAVA IS THE PRODUCT OF SUN";

   }  }

Code of JSP page

<%@page import="foo.gocha" %>

<html>

<head><title>Example of import

Attribute of page Directive in JSP</title></head>

<body>

<font size="10" color="blue">

<%

gocha ex = new gocha();

out.print(ex.show());

%>

</font>

</body>

</html>

 

Output

Advertisements

Advertisement

Posted on: June 11, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.