JSP class-1 recap by pnx67864

VIEWS: 4 PAGES: 7

									Classes 1-2-3-4       Talking to a Database in Jave
                      Java Server Pages, Databases, SQL, HTML Forms

Read:
DataBase-JSP-Topics [all pages]
JSP-examples: Bai text
JSP-DB-Overview (in PowerPoint)
DB-JSP-class-notes

Concepts: Database connection, driver, embedding SQL queries in programming
language, Java try/catch safety-net syntax apparatus, navigating result sets returned from
select query, connection & statement objects, HTML form interface & request object,
post versus get transparency.

Pragmatics: Query setup, query versus update execution methods, ResultSet(s),
retrieval by data type.

Topics:
   1. Server and DB communication
   2. Insert SQL
   3. Select SQL
   4. try/catch safety-net – sometimes bypass
   5. Logon table

Sequence: Recall Data Source Registration, Demonstrate Sp-05-Test000.jsp, 001 (002,
003) under (JSP-examples: Bai text - DB connection, SQL setup & execution, Insert,
Select, ResultSets), PowerPoint overview, Java try/catch construction & without
try/catch safety-net, interpreting Apache Error reports; relation between HTML form, JSP
program and background Access database; using hidden HTML fields.

In-class Exercises

       1.      Register database so its accessible by Java.
       2.      Connect to database from JSP with/without try/catch.
       3.      Insert a fixed record in database – one or more attributes.
       4.      Format results in HTML table (testCase014.jsp in chapter11 myjspapp).
       5.      Deleting records under Where condition.
       6.      ResultSets and Select * From Managers or other table; methods to
               navigate and access the table of results: r.next( ), r.getString("...")
       7.      Using an HTML form to request execution of a JSP program on a server.
       8.      Using an HTML form to send form data to the server – even if it is not
               accessed by the JSP program executed.
       9.      Using an HTML form to send data to a JSP program such as to Insert the
               data in a database table.
       10.     Sending back more substantial data – eg an HMTL Form page.
       11.     Sending back an HTML Form page that calls a different JSP program.
        12.      Sending hidden data from an HTML form to a JSP program.
        13.      Chaining JSP programs using information such as in hidden HTML fields.

Miscellaneous:

        1.    Using HTML Form with HTTP Post method rather than a Get method.
        2.    Modify/expand database table and ResultSet query.
        3.    Inserting multiple values from an HTML Form.
        4.    Shorthand JSP call using query-string directly in url with name=value pairs.
        5.    Intentionally misname DSN to illustrate use of try-catch syntax.


In-class Lab – Password protection using User Name & Password table
- related to 1st stage of Project:

        Figure out how to make a table of users and passwords that lets a JSP program
screen users. First try it with hardwired data, then try it with data from an HTML form.
Send different HTML response to browser depending on the outcome.
        Use an SQL Select query based on username and password to retrieve records
from a Password table. This requires using a ResultSet. Then use r.next ( ) to determine
the what to decide. Approval should succeed or fail depending on whether any record(s)
was retrieved – a result which is tantamount to whether the username/password
combination was valid (in the database) or not. In terms of a suitable Java control
structure an if ( ... ) { ... ; } else { ... ; } statement is probably the most appropriate. Return
an appropriate positive or negative response to the user accordingly. This problem does
not require that a password be set for the database itself.

Read especially:
      JSP-DB-Overview (in PowerPoint): slides 10-15
      DataBase-JSP-Topics: Connect a JSP to an Access Database
      DataBase-JSP-Topics: Insert Records in Database using JSP
      DataBase-JSP-Topics: Inserting Data from an HTML Form in Database
      using JSP
      DataBase-JSP-Topics: Retrieve Data from Database - JSP ResultSets
      DataBase-JSP-Topics: Apache Tomcat - common error reports:
      Also see Apache status reports in: Java-Server-Pages-Topics
Notes on Project:

1.  What the tables in the database look like – project2005.mdb
2.  Illustrate program activity [p00, p011.jsp] for one approach
3.  See Project2005.ppt under Sp2005 Assignments for multi-page approach.
4.  Overview multi-page slides carefully.
5.  Check syntax for transferring to a new jsp program and sending it data –
    beware the quotes !
6. Creating and sending HTML with out.println
7. Writing to dos prompt for separate display with System.out.println
8. Logic and tracing of while/switch control Logic – rationale for control Logic
9. Need to execute ---.next() to return even a single datum.
10. Data conversion for string to Integer
11. Hidden data fields that indicate current user and question number
12. Updating score; s1.equals(s2) syntax for strings; Update SQL syntax
13. Last answered question number, versus current question number, versus next
    question number.
14. Updating next field's value in database

p00.html
p011.jsp
cases 2, 3, 4 especially

PPT overview of Project: q00.html, qJSP2.jsp, qJSP3.jsp


1. What the tables in the database look like – project2005.mdb
2. Illustrate program activity [p00, p011.jsp] for one approach
6. Creating and sending HTML with out.println
8. Logic and tracing of while/switch control Logic – rationale for control Logic
9. Need to execute ---.next() to return even a single datum.
10. Data conversion for string to Integer

11. Hidden data fields that indicate current user and question number
13. Last answered question number, versus current question number, versus next
    question number.
14. Updating next field's value in database
12. Updating score; s1.equals(s2) syntax for strings; Update SQL syntax


3. See Project2005.ppt under Sp2005 Assignments for multi-page approach.
4. Overview multi-page slides carefully.
5. Check syntax for transferring to a new jsp program and sending it data –
   beware the quotes !
7. Writing to dos prompt for separate display with System.out.println
First 20 - ???

1. 10:00 -10:20 Sit in on IT 202: Henry Hudson High School, Group 1
       talk about - Othello - Phillip Kroge - talk to Philip about where's he's
       from – cross-country trip – Joanna - Kevin

            - a little on the PPT slides to IT students
Ten Minutes:

2. 10:25 - 10:35 Sit in on IT 202: Henry Hudson High School, Group 2
        talk - - Math Quiz – Brenda
       - Funny Pictures HW – Kevin

              - demo Testx to IT students

3. 10:40 - 10:50 Sit in on IT 202 Monmouth County Vocational High School
       talk – Rob Taschler - Terrorist web site
        – Computer Forensics – Bob Statica – Network Security
        – Mike deLucia Independent Study on Network Security
       - talk about - Othello - Rowena - computer play

      - implementation questions 11-12 to IT students


4. 10:55 - 11:05 Sit in on IT 202: Keyport High School, Group 1
       - Funny Pictures HW – Kevin
        talk – Aruna - Timed President Quiz – from Lithuania – doesn't do timed
        quiz ! – but its fun.

      - implementation questions 11-12 to IT students

5. 11:10 - 11:20 Sit in on IT 202: Keyport High School, Group 2
                 - Othello - Phillip Kroge -
                 - Othello- Billy G - nice GUI
                 - Funny Pictures – Kevin

2nd Class:

6. 11:40 - 11:55     Sit in on IT 202:      Group         Manasquan High School
       talk   - Math Quiz - Brenda
              - Othello- Billy G - nice GUI
              - Othello - Phillip Kroge -
Chaining JSP programs using information such as in hidden HTML fields.

1. Underlying problem: server program does not remember you after it sends a page to
you, such as in response to a previous HTML Form request.

Explain this dramatically in terms of 2 users – with concurrent requests – and how do I
know who I am dealing with after I have sent back the question.....



2. To get around this it can embed hidden data in the page sent such as data previously
obtained from an earlier form.

Illustrate with:
         1. html with fields calling xx.jsp
         2. xx.jsp gets the fields data and includes as hidden form data in html it returns



hidden html
send html
describe need for state info – dramatically
implement it: H1 => x1 => H2 [with hidden data from H1] => x2 [announces hidden
values] ...
access HW
operator order and + v. *

next() has to be executed – else get null reference
Previous semesters:
Fall 2004 - Classes 1-2 Java Server Pages, SQL, HTML Forms and Databases

           Read Databases-JSP-Topics.doc link on website for details.

Remarks
           Assignment 08: MS Access.
           Assignment 09: see below.

           Basic Project: see website under Assignments.
           You are strongly encouraged to devise a creative alternative Project.

           Refer to Schedule for due dates.

In-class Exercises
       6. Register database so its accessible by Java.
       7. Connect to database from JSP without/with try/catch.
       8. Insert a fixed record in a database – one or more attributes.
       9. Insert single datum from an HTML Form (revise table as needed).
       10. Shorthand JSP call using query-string directly.
       11. Inserting multiple values from an HTML Form.
       12. Deleting records under Where condition.
       13. ResultSet and Select * From Managers ; r.next, r.getString
       14. Modify ResultSet query.
       15. Formatting results in HTML table.

PowerPoint overview – 10 minutes

In-class Lab – Password protection using User Name & Password table
This is Assignment 09:
        Figure out how to make a table of users and passwords that lets a JSP program
screen users. Use an SQL Select query based on username and password to retrieve
records from password table. This requires ResultSet. Then use r.next ( ) to determine
the 'outcome'. It succeeds or fails depending on whether any record(s) was retrieved –
which is tantamount to whether the username/password combination was valid or not. In
terms of a suitable Java control structure an if ( ... ) { ... ; } else { ... ; } statement is
probably the most appropriate. Return an appropriate positive or negative response to the
user accordingly. The solution does not require that a password be imposed on the
database itself.
Concepts
      Database connection, Java try/catch safety net apparatus, post v. get transparency.

Pragmatics
       Query setup, ResultSet(s), retrieval by data type, query-string shortcuts with
hardwired data.



   1.   get logic
   2.   pwd
   3.   question
   4.   question by number
   5.   sequence of questions

								
To top