+ All Categories
Home > Documents > OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs...

OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs...

Date post: 18-Jan-2016
Category:
Upload: loraine-fox
View: 227 times
Download: 0 times
Share this document with a friend
24
OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add SQL examples Summary Version 1.1 Nov 2009 Slide 1 [email protected]/ [email protected]
Transcript
Page 1: OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.

OOSSE Week 8JSP models Format of lecture: Assignment context JSP models

JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add SQL examples

Summary

Version 1.1 Nov 2009Slide [email protected]/[email protected]

Page 2: OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.

OOSSE Week 8Assignment contextWhat have you got to develop? To answer this ….You need to

study the assignment specification carefully – the wording is deliberate

“Development of Application (20%)The site requires a Java Application that will allow the user to do the following based on the above scenario: -

Register as a member of the site/show member details/update member details

Enter an orderUpdate an orderView ordersDelete orders”

Slide [email protected]/[email protected]

Page 3: OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.

OOSSE Week 8Assignment Context

Register as a member of the site/show member details/update member details

Can you do this?YES with JSPs from last week and this week

Add JSPView JSPUpdate JSP

Slide [email protected]/[email protected]

Page 4: OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.

OOSSE Week 8Assignment Context

Enter an order

Update an order

View orders

Delete orders

Can you do this – yes but hold on a minute – what do the actions above imply? Ans: A shopping cart…..rather than build your own….use one that is already available …..Mal’s E-Commerce

Slide [email protected]/[email protected]

Page 5: OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.

OOSSE Week 8Anything elseYes ….How to store the orders that members

make…in a databaseWe can use Access to store members details

via our JSPsBut for orders is that necessary?So search for OO add on functionality…the

result? mOrders – free download

Slide [email protected]/[email protected]

Page 6: OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.

OOSSE Week 8

Version 1.0 Nov 2007Slide [email protected]/[email protected]

Page 7: OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.

OOSSE Week 8

Version 1.0 Nov 2007Slide [email protected]/[email protected]

Page 8: OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.

OOSSE Week 8JSP Built-in ObjectsJSPs have access to several objects that we

can use when processing a request from a browser and then generate a dynamic response.

There are eight in all:request out response pagecontextsession applicationconfig page

Slide [email protected]/[email protected]

Page 9: OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.

OOSSE Week 8Built-in objects You will see these objects being used in the

examples provided Request objects methods allow us to access

information about: The user HTTP headers Client’s machine Request URL and parameters.

Slide [email protected]/[email protected]

Page 10: OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.

OOSSE Week 8Built-in objectsResponse objects methods allow access to:

Setting HTTP headersSet cookiesEncode session information into URLs

Version 1.0 Nov 2007Slide [email protected]/[email protected]

Page 11: OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.

OOSSE Week 8Built-in objectsOut object - has methods to generate and

control output to the browserPageContext object - has page attributesPage object - represents the servlet instance

i.e. the object generated from having compiled the JSP <mention about Servlets>

Application object - used for extracting information about the lifecycle of the Servlet

Version 1.0 Nov 2007Slide [email protected]/[email protected]

Page 12: OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.

OOSSE Week 8

Reminder - The Structure of JSPsAn initial selection of tags to get to know (Scriptlet

Tags = v. important!!!)

<% //embed Java code %>

Used for embedding blocks of Java code into JSPsScriptlets provide control structures like decision (if

and switch) and iteration control structures (for and while)

Version 1.0 Nov 2007Slide [email protected]/[email protected]

Page 13: OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.

OOSSE Week 8Structure of JSPsDeclaration Tags – also important.

<%! // Variable declaration - method declaration %>

Used for declaring variables and methods. For example:<%! HttpSession ses = null; %><%! public String whereFrom(HttpServletRequest req)

{ ses = req.getSession(); return req.getRemoteHost();}

%><% out.print("Hi there, I see that you are coming in from "); %><%= whereFrom(request) %>

Version 1.0 Nov 2007Slide [email protected]/[email protected]

Page 14: OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.

OOSSE Week 8Structure of JSPsExpression Tags

<%= java expression %>

Used for inserting the value of a Java expression into JSPse.g. <td><%= rs.getString("LastName") %></td>

Version 1.0 Nov 2007Slide [email protected]/[email protected]

Page 15: OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.

OOSSE Week 8Structure of JSPs Directive Tags – used to provide information to the JSP server. There are three directives:

page include taglib

We will only review the page and include directive Page Directive - used to set properties of the JSP. E.g. what

packages it imports from the Java library or is an error page

<%@ page page_attributes %> e.g. <%@ page import="java.sql.*" %><%@ page errorPage=“myErrorPage.jsp" %>

Version 1.0 Nov 2007Slide [email protected]/[email protected]

Page 16: OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.

OOSSE Week 8

JSP Action Tags – Useful for assignmentAction tags are used to perform actions when a JSP page is

requested by a browserThere are six JSP action tags:

useBeansetPropertygetPropertyIncludeForwardplugin

We will review the following two:forward – this week (week 8)Include – next week (week 9)

Version 1.0 Nov 2007Slide [email protected]/[email protected]

Page 17: OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.

OOSSE Week 8forward Action

<jsp:forward page=“Relative_URL” />

Used to forward the request to another JSP – see diagram on next page

This will forward the current request object to the specified fileWhen a forward tag is encountered, the JSP engine doesn't

process the remainder of the current JSP fileAnything that has been written into the output buffer by the

current JSP file will be lost

Version 1.0 Nov 2007Slide [email protected]/[email protected]

Page 18: OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.

OOSSE Week 8Forward model Forward model

Version 1.0 Nov 2007Slide [email protected]/[email protected]

JSP

JSP

Client Request

DATABASE

The JSP parses the input from

the client form and updates the

databaseHTTP Server - Tomcat

HTML Form

SQL

Response

HTML Form

Page 19: OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.

OOSSE Week 8Demos in jw5 server folderCRUD examples this week and next –

Create(add);Retrieve(view/get);Adding information to a database

Demo of a add JSP (addtousers.jsp)http://trentdev:8080/examples/jw5/addtousers.jsp

Retrieving (getting) information from the Guestbook database with JSPs

Demo of a simple Get JSP (SimpleGetUserExample.jsp)http://trentdev:8080/examples/jw5/SimpleGetUserExample.jsp

Demo of a user input version of get (GetUserUsingInputExample.jsp)

http://trentdev:8080/examples/jw5/GetUserUsingInputExample.jsp

Slide [email protected]/[email protected]

Page 20: OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.

OOSSE Week 8addtousers.jsp

Version 1.0 Nov 2007Slide [email protected]/[email protected]

Page 21: OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.

OOSSE Week 8SimpleGetUserExample.jsp

Version 1.0 Nov 2007Slide [email protected]/[email protected]

Page 22: OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.

OOSSE Week 8GetUserUsingInputExample.jsp

Version 1.0 Nov 2007Slide [email protected]/[email protected]

Page 23: OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.

OOSSE Week 8InputGuestsv2.html – an HTML form that calls a JSP and then forwards back to another page

Version 1.0 Nov 2007Slide [email protected]/[email protected]

Page 24: OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.

OOSSE Week 8SummaryYou have learnt more about the structure of

JSPsLearning from examples is good

You have seen an Add something JSPYou have seen a more sophisticated view

something JSP (compared to last week with the simple guest listing)

You are now in a position to apply this knowledge to the assignment task

Version 1.0 Nov 2007Slide [email protected]/[email protected]


Recommended