Java Reference
In-Depth Information
directive
Finally, let us introduce one more JSP tag, the directive . In general terms, directives
instruct the compiler how to process a JSP program. Examples include the definition
of our own tags, including the source code of other files, and importing packages. The
syntax for directives is as follows:
<%@
Directives
%>
In this introduction, we will cover only the page import directive. The purpose of this
directive is the same as the normal Java import statement, but the syntax is slightly
different. First, we identify the directive and then specify the packages to import inside
a string. Multiple packages are separated by a comma, e.g.,
page import
<%@
page import="java.util.*,java.sql.*"
%>
A JSP program that uses Derby to create an embedded database is shown in
Display 19.24. The page import directive is used to import the necessary SQL packages.
The program in Display 19.24 is almost identical to the stand-alone program in
Display 19.12, except all of the code has been moved into a scriptlet. If the JSP
program is in a file named CreateDB.jsp , then it would be invoked by navigating to
http://localhost:8080/CreateDB.jsp . The database files on a GlassFish server will
be created in <glassfish_home>\domains\domain1\config if you do not specify a
pathname. If you run the program more than once, then it will throw an exception the
second time, because the database table names already exists and cannot be created again.
If you wish to start over with a new database, then you can delete the BookDatabase
directory in the <glassfish_home>\domains\domain1\config directory.
Display 19.24
JSP Program to Create a Derby Database and Table (part 1 of 3)
Directive to import the Java
SQL packages.
1 <%@ page import="java.sql.*" %>
2 <html>
3 <title>Create New Database</title>
4 <body>
5 <H2>Create New Database</h2>
6 <p>
7 This program creates a new Derby database named 'BookDatabase'
8 and puts sample data into the 'person' table.
9 </p>
10 <%
11 String driver = "org.apache.derby.jdbc.EmbeddedDriver";
12 String protocol = "jdbc:derby:";
Refer to Display 19.12 for an
explanation of the database
code in this scriptlet.
(continued)
 
Search WWH ::




Custom Search