?? books.jsp
字號:
<!-- Tutorial 32: books.jsp -->
<!-- Displays a form. -->
<%-- import java.sql.* for database classes --%>
<%@ page import = "java.sql.*" %>
<!-- begin HTML document -->
<html>
<!-- specify HTML head element -->
<head>
<!-- specify page title -->
<title>Book List</title>
</head>
<!-- begin body of document -->
<body>
<h1>Available Books</h1>
<!-- create form -->
<form method = "post" action = "bookInformation.jsp">
<p>Select a book from the list and click the button to view
the selected book's information</p>
<!-- create list that contains book titles -->
<select name = "bookTitle">
<%-- begin JSP scriptlet to connect to database --%>
<%
// setup database connection
try
{
// specify database location
System.setProperty( "db2j.system.home",
"C:\\Examples\\Tutorial29\\Databases" );
// load Cloudscape driver
Class.forName( "com.ibm.db2j.jdbc.DB2jDriver" );
// connect to database
Connection connection =
DriverManager.getConnection(
"jdbc:db2j:bookstore" );
// obtain list of titles
if ( connection != null )
{
Statement statement =
connection.createStatement();
ResultSet results = statement.executeQuery(
"SELECT title FROM products" );
// display book title
while ( results.next() )
{
String currentTitle =
results.getString( "title" );
%> <%-- end scriptlet to insert HTML --%>
<%-- use JSP expression to display book title --%>
<option><%= currentTitle %></option>
<% // continue scriptlet
} // end while loop
results.close(); // close result set
// close database connection
connection.close();
} // end if
} // end try
// catch SQLException
catch( SQLException exception )
{
out.println(
"Exception: " + exception + " occurred." );
}
%> <%-- end scriptlet --%>
</select>
<!-- create View Information button -->
<p><input type = "submit" value = "View Information"></p>
</form>
</body>
</html>
<!--
**************************************************************************
* (C) Copyright 1992-2004 by Deitel & Associates, Inc. and *
* Pearson Education, Inc. All Rights Reserved. *
* *
* DISCLAIMER: The authors and publisher of this book have used their *
* best efforts in preparing the book. These efforts include the *
* development, research, and testing of the theories and programs *
* to determine their effectiveness. The authors and publisher make *
* no warranty of any kind, expressed or implied, with regard to these *
* programs or to the documentation contained in these books. The authors *
* and publisher shall not be liable in any event for incidental or *
* consequential damages in connection with, or arising out of, the *
* furnishing, performance, or use of these programs. *
**************************************************************************
-->
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -