In this Section , we will discuss about the "import" attribute of a JSP & its use in JSP page.
In this Section , we will discuss about the "import" attribute of a JSP & its use in JSP page.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