Download presentation
Presentation is loading. Please wait.
Published byHollie Stewart Modified over 9 years ago
1
Indy Java User’s Group March 27, 2001 Sallie Mae 6:00p.m
2
Mission Statement Promote the use of the Java language and components across all levels of interest in the greater Indianapolis area, by serving as a resource for knowledge, experience and career opportunities.
3
Agenda Pizza Welcome!!6:00-6:15 Announcements6:15-6:30 Joe Caron6:30-7:30 Quality Tip7:30-7:45 Performance Tip7:45-8:00
4
Announcements Next Meeting - April 24, 2002 Mike Burba – Sun ONE Java Jam - Kurt Kirkham Feedback Results eGroups.yahoo.com http://groups.yahoo.com/group/indyJug http://groups.yahoo.com/group/indyjug_opensource BOT Contest – Deadline March 31 http://developer.digi-net.com
5
Announcements CRN – Annual Survey 1) Call 1-800-939-6206 2) Ask for Amy Johnson 3) Request your gift – Sweatshirt Cap T-Shirt Visit www.metafacts.com Visit www.crn.com
6
Presentation Lineup Mark Steenbarger Indy Jug Joe Caron KingArthurFlour.com Mike Slattery SearchSoft.net Frank Morton Base2Inc.com
7
JDBC & Servlets/JSP Joe Caron Indianapolis Java Users Group March 27, 2002
8
Database access through the web n Sample application overview n JDBC Fundamentals n Servlet/JSP Fundamentals n Implementation & sample code n Pitfalls, Surprises, Work-arounds
9
Sample Application n Message Board n Membership Based n Pass membership info to catalogue site for “quick check-out” n Accumulate “bakers points” redeemable against online orders n Member “recipe box”
10
Sample Application n JSP for presentation n Servlets & other java for app logic n MySQL as the RDBMS n Tomcat as Servlet/JSP container n Linux (Red Hat 6.2)
11
Sample Application n www.bakingcircle.com www.bakingcircle.com n Staging Server Staging Server n Entity Relationship Diagram Entity Relationship Diagram n Application Diagram Application Diagram n Presentation Diagram Presentation Diagram
12
JDBC Fundamentals n Standard means of accessing any RDBMS for which there is a JDBC driver n Drivers which implement Sun’s JDBC standard capture a DB connection as Java Object n Change DBMS without changing any application code (except driver) n Sun JDBC API overview Sun JDBC API overview
13
JDBC Fundamentals n Key objects u Connection u Statement u PreparedStatement u ResultSet / Rowset u ResultSet MetaData u DB MetaData
14
JDBC Fundamentals n Sun JDBC overview Sun JDBC overview n Basic Example - MySQL Basic Example - MySQL n Basic Example - ORACLE Basic Example - ORACLE n Statement vs. PreparedStatement Statement vs. PreparedStatement n Stand-Alone Example Stand-Alone Example n API Documentation API Documentation n JDBC Optional: DataSource JDBC Optional: DataSource
15
Servlet/JSP Fundamentals n “Servlet Container” (Tomcat, for example), working in conjunction with Web server (Apache or IIS) n Integrated in J2EE compliant server (BEA, Iplanet, Orion) n Many options regarding both the products and how to set them up Many options
16
Servlet/JSP Fundamentals Common Set-Up Servlet Engine Web Server Client.html & others.jsp & /servlet/ Redirect based on conf file conf file Common directory structure
17
Servlet/JSP Fundamentals n Servlets like any other Java class, except: n Must extend HttpServlet n Must contain a doPost or doGet method n Come equipped to handle the laborious points of http n Http requests and responses are made into Java objects n Best alternative to traditional CGI
18
Servlet/JSP Fundamentals n Anatomy of a Servlet u Optional init method, executes the first time a servlet is invoked u doGet/doPost methods execute when request is made u method signature accepts http request and response as parameters u Optional destroy method u www.servlets.com Samples www.servlets.com Samples
19
Servlet/JSP Fundamentals n One instance of Servlet for each Servlet name n Same instance serves all requests to that name n Instance members persist across all requests to that name. n Local /block variables in doPost & doGet are unique to each request
20
Servlet/JSP Fundamentals n Instance members vs local variables Instance members vs local variables n Major request and response methods Major request and response methods n More major request and response methods More major request and response methods n Making use of servlet context Making use of servlet context n Keeping sessions: the bane of all Web programming Keeping sessions: the bane of all Web programming
21
JSPs: Servlets in disguise... n Better alternative for presentation. n Insert special brackets into HTML page to mark off Java code. n A JSP is compiled into a Servlet the first time it is called. n Crash course in JSP syntax
22
JSP as presentation model Servlet Performs the hard work Client request JSP Successful results Helper objects Persistent “bean” objects DB Connections, etc JSP Unsuccessful results App logic Presentation Subsequent client request Simple calls to bean properties No servlet need if bean still set
23
JSP alternatives n JSP can still result in unwieldy code creeping into HTML n Most HTML editors don’t like it n JSP:Taglibs and other “templating” programs may help. n Much depends on how HTML documents are produced and what business logic you are presenting
24
In Depth Examples n Encapsulation of SQL calls n List results and view thread detail n Post reply and add to favorites n Set all bean properties w/ request n Edit users n Query central
25
Pitfalls, surprises, and work-arounds n HTTP works via requests and responses. Client caching of responses poses a problem. n Guard against evil use of the “back” button n Don’t assume everyone’s client will respond properly to the “defaults” n Guard against easy spoofs of any GET request which alters data.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.