Title: Indy Java User
1Indy Java Users Group
March 27, 2001 Sallie Mae 600p.m
2Mission 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.
3Agenda
- Pizza Welcome!! 600-615
- Announcements 615-630
- Joe Caron 630-730
- Quality Tip 730-745
- Performance Tip 745-800
4Announcements
- 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
5Announcements
- 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
6Presentation Lineup
- Mark Steenbarger
- Indy Jug
- Joe Caron
- KingArthurFlour.com
- Mike Slattery
- SearchSoft.net
- Frank Morton
- Base2Inc.com
7JDBC Servlets/JSP
- Joe Caron
- Indianapolis Java Users Group
- March 27, 2002
8Database access through the web
- Sample application overview
- JDBC Fundamentals
- Servlet/JSP Fundamentals
- Implementation sample code
- Pitfalls, Surprises, Work-arounds
9Sample Application
- Message Board
- Membership Based
- Pass membership info to catalogue site for quick
check-out - Accumulate bakers points redeemable against
online orders - Member recipe box
10Sample Application
- JSP for presentation
- Servlets other java for app logic
- MySQL as the RDBMS
- Tomcat as Servlet/JSP container
- Linux (Red Hat 6.2)
11Sample Application
- www.bakingcircle.com
- Staging Server
- Entity Relationship Diagram
- Application Diagram
- Presentation Diagram
12JDBC Fundamentals
- Standard means of accessing any RDBMS for which
there is a JDBC driver - Drivers which implement Suns JDBC standard
capture a DB connection as Java Object - Change DBMS without changing any application code
(except driver) - Sun JDBC API overview
13JDBC Fundamentals
- Key objects
- Connection
- Statement
- PreparedStatement
- ResultSet / Rowset
- ResultSet MetaData
- DB MetaData
14JDBC Fundamentals
- Sun JDBC overview
- Basic Example - MySQL
- Basic Example - ORACLE
- Statement vs. PreparedStatement
- Stand-Alone Example
- API Documentation
- JDBC Optional DataSource
15Servlet/JSP Fundamentals
- Servlet Container (Tomcat, for example),
working in conjunction with Web server (Apache or
IIS) - Integrated in J2EE compliant server (BEA,
Iplanet, Orion) - Many options regarding both the products and how
to set them up
16Servlet/JSP FundamentalsCommon Set-Up
Redirect based on conf file
Web Server
.html others
.jsp /servlet/
Client
Common directory structure
17Servlet/JSP Fundamentals
- Servlets like any other Java class, except
- Must extend HttpServlet
- Must contain a doPost or doGet method
- Come equipped to handle the laborious points of
http - Http requests and responses are made into Java
objects - Best alternative to traditional CGI
18Servlet/JSP Fundamentals
- Anatomy of a Servlet
- Optional init method, executes the first time a
servlet is invoked - doGet/doPost methods execute when request is made
- method signature accepts http request and
response as parameters - Optional destroy method
- www.servlets.com Samples
19Servlet/JSP Fundamentals
- One instance of Servlet for each Servlet name
- Same instance serves all requests to that name
- Instance members persist across all requests to
that name. - Local /block variables in doPost doGet are
unique to each request
20Servlet/JSP Fundamentals
- Instance members vs local variables
- Major request and response methods
- More major request and response methods
- Making use of servlet context
- Keeping sessions the bane of all Web programming
21JSPs Servlets in disguise...
- Better alternative for presentation.
- Insert special brackets into HTML page to mark
off Java code. - A JSP is compiled into a Servlet the first time
it is called. - Crash course in JSP syntax
22JSP as presentation model
Servlet Performs the hard work
Helper objects Persistent bean objects DB
Connections, etc
App logic
Simple calls to bean properties
Client request
JSP Successful results
JSP Unsuccessful results
Subsequent client request
Presentation
No servlet need if bean still set
23JSP alternatives
- JSP can still result in unwieldy code creeping
into HTML - Most HTML editors dont like it
- JSPTaglibs and other templating programs may
help. - Much depends on how HTML documents are produced
and what business logic you are presenting
24In Depth Examples
- Encapsulation of SQL calls
- List results and view thread detail
- Post reply and add to favorites
- Set all bean properties w/ request
- Edit users
- Query central
25Pitfalls, surprises, and work-arounds
- HTTP works via requests and responses. Client
caching of responses poses a problem. - Guard against evil use of the back button
- Dont assume everyones client will respond
properly to the defaults - Guard against easy spoofs of any GET request
which alters data.
26(No Transcript)
27(No Transcript)