Danh mục tài liệu

Java Server Pages: A Code-Intensive Premium Reference- P7

Số trang: 10      Loại file: pdf      Dung lượng: 319.95 KB      Lượt xem: 8      Lượt tải: 0    
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Java Server Pages: A Code-Intensive Premium Reference- P7:Before you begin reading Pure JSP Java Server Pages, you might want to take a look at its basicstructure. This should help you outline your reading plan if you choose not to read the text from cover tocover. This introduction gives you an overview of what each chapter covers.
Nội dung trích xuất từ tài liệu:
Java Server Pages: A Code-Intensive Premium Reference- P7 } }%>Note A key thing to note is the HTML code that is intermingled throughout the scriptlet code. This is done by closing the scriptlet block with the %> symbol, inserting the HTML code, and then reopening the scriptlet block with the config = pageContext.getServletConfig();session = pageContext.getSession();out = pageContext.getOut();// begin out.write( JSPJDBC + Example 1 ); );// end// beginout.write( );// end// begin [file=D:\JDBCExample.jsp;// from=(11,2);to=(33,6)]Connection con = null;try { // Load the Driver class file Class.forName(sun.jdbc.odbc.JdbcOdbcDriver); // Make a connection to the ODBC datasource con = DriverManager.getConnection( jdbc:odbc:Movie Catalog, , ); // Create the statement Statement statement = con.createStatement();// Use the created statement to SELECT the DATA // FROM the Titles Table. ResultSet rs = statement.executeQuery(SELECT * + FROM Titles); // Iterate over the ResultSet // end // begin out.write( + + TitleRating Price - 62 - Quantity ); // end // begin [file=D:\JDBCExample.jsp; // from=(38,8);to=(89,0)] while ( rs.next() ) { // get the title_name, which is a String out.println( + rs.getString(title_name) + ); // get the rating out.println( + rs.getString(rating) + ); // get the price out.println( + rs.getString(price) + ); // get the quantity out.println( + rs.getString(quantity) + ); }// Close the ResultSetrs.close();}catch (IOException ioe) { out.println(ioe.getMessage());}catch (SQLException sqle) { out.println(sqle.getMessage());}catch (ClassNotFoundException cnfe) { out.println(cnfe.getMessage());}catch (Exception e) { out.println(e.getMessage());} - 63 - finally { try { if ( con != null ) { // Close the con no matter what con.close(); } } catch (SQLException sqle) { out.println(sqle.getMessage()); } } // end // begin out.write( ); // end } catch (Exception ex) { if (out.getBufferSize() != 0) out.clear(); pageContext.handlePageException(ex); } finally { out.flush(); jspxFactory.releasePageContext(pageContext); }}You will notice as you look through the generated _jspMethod() method that the generated JDBC codeis almost verbatim to your JSP scriptlet code. That is really all there is to it. In Chapter 15, JSP and XML,we will examine a more efficient method of database interaction by incorporating a JDBC connection poolusing a JavaBean.SummaryIn this chapter, we covered the basics of the JDBC and its characteristics, saw how to set up a JDBCdriver, and examined how you can incorporate the JDBC into a JSP. We also briefly examined how youcan break up your scriptlet code by embedding your HTML code into it.This chapter marks the end of Part I, Conceptual Reference, which introduces JSP concepts. In Part II,Techniques Reference, we examine some JSP techniques that really dig into what you have justlearned. The next 14 chapters demonstrate how you can put these concepts to practical use. - 64 -Part II: Techniques ReferenceChapter ListChapter 5: Configuring the JSP ServerChapter 6: Handling JSP ErrorsChapter 7: Using the include DirectiveChapter 8: JavaServer Pages and InheritanceChapter 9: Using the JSPs Implicit ObjectsChapter 10: Using JSP Standard ActionsChapter 11: JSPs and JavaBean ScopeChapter 12: JSP and HTML FormsChapter 13: JSP and a Shopping CartChapter 14: JSP and a JDBC Connection Pool BeanChapter 15: JSP and XMLChapter 16: JSP Communication with ServletsChapter 17: JSP and JavaMailChapter 5: Configuring the JSP ServerOverviewTomcat is the flagship product of the Apache Software Foundations Jakarta Project. It is intended to be aworld-class implementation of Suns Java Servlet SDK 2.2 and JavaServer Pages 1.1 specifications.Tomcat is, at the time of this writing, the only released implementation of both of these specifications.Because of Tomcats compliance with the latest specifications, it will be the server used throughout thi ...