Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

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 SQL examples Summary Version 1.1 Nov 2009 Slide 1 j.c.westlake@staffs.ac.uk/n.a.shulver@staffs.ac.uk

2 OOSSE Week 8 Assignment context What 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 order Update an order View orders Delete orders” Slide 2 j.c.westlake@staffs.ac.uk/n.a.shulver@staffs.ac.uk

3 OOSSE Week 8 Assignment 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 JSP View JSP Update JSP Slide 3 j.c.westlake@staffs.ac.uk/n.a.shulver@staffs.ac.uk

4 OOSSE Week 8 Assignment 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 4 j.c.westlake@staffs.ac.uk/n.a.shulver@staffs.ac.uk

5 OOSSE Week 8 Anything else Yes ….How to store the orders that members make…in a database We can use Access to store members details via our JSPs But for orders is that necessary? So search for OO add on functionality…the result? mOrders – free download Slide 5 j.c.westlake@staffs.ac.uk/n.a.shulver@staffs.ac.uk

6 OOSSE Week 8 Version 1.0 Nov 2007 Slide 6 j.c.westlake@staffs.ac.uk/n.a.shulver@staffs.ac.uk

7 OOSSE Week 8 Version 1.0 Nov 2007 Slide 7 j.c.westlake@staffs.ac.uk/n.a.shulver@staffs.ac.uk

8 OOSSE Week 8 JSP Built-in Objects JSPs 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: requestout responsepagecontext sessionapplication configpage Slide 8 j.c.westlake@staffs.ac.uk/n.a.shulver@staffs.ac.uk

9 OOSSE Week 8 Built-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 9 j.c.westlake@staffs.ac.uk/n.a.shulver@staffs.ac.uk

10 OOSSE Week 8 Built-in objects Response objects methods allow access to: Setting HTTP headers Set cookies Encode session information into URLs Version 1.0 Nov 2007 Slide 10 j.c.westlake@staffs.ac.uk/n.a.shulver@staffs.ac.uk

11 OOSSE Week 8 Built-in objects Out object - has methods to generate and control output to the browser PageContext object - has page attributes Page object - represents the servlet instance i.e. the object generated from having compiled the JSP Application object - used for extracting information about the lifecycle of the Servlet Version 1.0 Nov 2007 Slide 11 j.c.westlake@staffs.ac.uk/n.a.shulver@staffs.ac.uk

12 OOSSE Week 8 Reminder - The Structure of JSPs An initial selection of tags to get to know (Scriptlet Tags = v. important!!!) Used for embedding blocks of Java code into JSPs Scriptlets provide control structures like decision (if and switch) and iteration control structures (for and while) Version 1.0 Nov 2007 Slide 12 j.c.westlake@staffs.ac.uk/n.a.shulver@staffs.ac.uk

13 OOSSE Week 8 Structure of JSPs Declaration Tags – also important. Used for declaring variables and methods. For example: <%!public String whereFrom(HttpServletRequest req) { ses = req.getSession(); return req.getRemoteHost(); } %> Version 1.0 Nov 2007 Slide 13 j.c.westlake@staffs.ac.uk/n.a.shulver@staffs.ac.uk

14 OOSSE Week 8 Structure of JSPs Expression Tags Used for inserting the value of a Java expression into JSPs e.g. Version 1.0 Nov 2007 Slide 14 j.c.westlake@staffs.ac.uk/n.a.shulver@staffs.ac.uk

15 OOSSE Week 8 Structure 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 e.g. Version 1.0 Nov 2007 Slide 15 j.c.westlake@staffs.ac.uk/n.a.shulver@staffs.ac.uk

16 OOSSE Week 8 JSP Action Tags – Useful for assignment Action tags are used to perform actions when a JSP page is requested by a browser There are six JSP action tags: useBean setProperty getProperty Include Forward plugin We will review the following two: forward – this week (week 8) Include – next week (week 9) Version 1.0 Nov 2007 Slide 16 j.c.westlake@staffs.ac.uk/n.a.shulver@staffs.ac.uk

17 OOSSE Week 8 forward Action Used to forward the request to another JSP – see diagram on next page This will forward the current request object to the specified file When a forward tag is encountered, the JSP engine doesn't process the remainder of the current JSP file Anything that has been written into the output buffer by the current JSP file will be lost Version 1.0 Nov 2007 Slide 17 j.c.westlake@staffs.ac.uk/n.a.shulver@staffs.ac.uk

18 OOSSE Week 8 Forward model lForward model Version 1.0 Nov 2007 Slide 18 j.c.westlake@staffs.ac.uk/n.a.shulver@staffs.ac.uk JSP Client Request DATABASE The JSP parses the input from the client form and updates the database HTTP Server - Tomcat HTML Form SQL Response

19 OOSSE Week 8 Demos in jw5 server folder CRUD 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 19 j.c.westlake@staffs.ac.uk/n.a.shulver@staffs.ac.uk

20 OOSSE Week 8 addtousers.jsp Version 1.0 Nov 2007 Slide 20 j.c.westlake@staffs.ac.uk/n.a.shulver@staffs.ac.uk

21 OOSSE Week 8 SimpleGetUserExample.jsp Version 1.0 Nov 2007 Slide 21 j.c.westlake@staffs.ac.uk/n.a.shulver@staffs.ac.uk

22 OOSSE Week 8 GetUserUsingInputExample.jsp Version 1.0 Nov 2007 Slide 22 j.c.westlake@staffs.ac.uk/n.a.shulver@staffs.ac.uk

23 OOSSE Week 8 InputGuestsv2.html – an HTML form that calls a JSP and then forwards back to another page Version 1.0 Nov 2007 Slide 23 j.c.westlake@staffs.ac.uk/n.a.shulver@staffs.ac.uk

24 OOSSE Week 8 Summary You have learnt more about the structure of JSPs Learning from examples is good You have seen an Add something JSP You 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 2007 Slide 24 j.c.westlake@staffs.ac.uk/n.a.shulver@staffs.ac.uk


Download ppt "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."

Similar presentations


Ads by Google