DT228/3 Web Development multi page applications/ sharing data.

Slides:



Advertisements
Similar presentations
Lecture 6/2/12. Forms and PHP The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input When dealing with HTML forms.
Advertisements

DT228/3 Web Development WWW and Client server model.
Copyright 2004 Monash University IMS5401 Web-based Systems Development Topic 2: Elements of the Web (g) Interactivity.
Server-Side vs. Client-Side Scripting Languages
DT211/3 Internet Application Development JSP: Processing User input.
DT211/3 Internet Application Development
Dynamic Web Pages. Web Programming  All our web pages so far have been static pages. 1. We create a web page 2. We upload it to the web server 3. People.
DT228/3 Web Development JSP: Directives and Scripting elements.
DT228/3 Web Development Databases. Database Almost all web application on the net access a database e.g. shopping sites, message boards, search engines.
XP Tutorial 9 New Perspectives on JavaScript, Comprehensive1 Working with Cookies Managing Data in a Web Site Using JavaScript Cookies.
1 The World Wide Web. 2  Web Fundamentals  Pages are defined by the Hypertext Markup Language (HTML) and contain text, graphics, audio, video and software.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
COMPUTER TERMS PART 1. COOKIE A cookie is a small amount of data generated by a website and saved by your web browser. Its purpose is to remember information.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Overview of JSP Technology. The need of JSP With servlets, it is easy to – Read form data – Read HTTP request headers – Set HTTP status codes and response.
ASHIMA KALRA.  INTRODUCTION TO JSP INTRODUCTION TO JSP  IMPLICIT OBJECTS IMPLICIT OBJECTS  COOKIES COOKIES.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
CIS 375—Web App Dev II ASP.NET 2 Introducing Web Forms.
CHAPTER 12 COOKIES AND SESSIONS. INTRO HTTP is a stateless technology Each page rendered by a browser is unrelated to other pages – even if they are from.
ABSTRACT Zirous Inc. is a growing company and they need a new way to track who their employees working on various different projects. To solve the issue.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
Server-side Scripting Powering the webs favourite services.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
DATA COMMUNICATION DONE BY: ALVIN SAMPATH CARLVIN SAMPATH.
Working with Cookies Managing Data in a Web Site Using JavaScript Cookies* *Check and comply with the current legislation regarding handling cookies.
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
CSE 154 LECTURE 12: COOKIES. Including files: include include("filename"); PHP include("header.html"); include("shared-code.php"); PHP inserts the entire.
CSCI 6962: Server-side Design and Programming Introduction to Java Server Faces.
CS453: State in Web Applications (Part 1) State in General Sessions (esp. in PHP) Prof. Tom Horton.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
COMP3121 E-Commerce Technologies Richard Henson University of Worcester November 2011.
Chapter 8 Cookies And Security JavaScript, Third Edition.
C# Tutorial -1 ASP.NET Web Application with Visual Studio 2005.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
1 Maryland ColdFusion User Group Session Management December 2001 Michael Schuler
SRM Free Text Carts SRM_SHO_303 SRM Free Text Carts.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
HTML Basics BCIS 3680 Enterprise Programming. Web Client/Server Architecture 2  Your browser (the client) requests a Web page from a remote computer.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
1 אירוע אמאזון. 2 שלבי הפיתוח עם דיאגרמות UML 3 אמאזון תרשים תוכן.
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
PHP. $_GET / $_POST / $_SESSION PHP uses predefined variables to provide access to important information about the server and requests from a browser.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
Sessions in PHP – Page 1 of 13CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: Sessions in PHP Reading: Williams.
Web Database Programming Week 7 Session Management & Authentication.
Registration Solutions for your Event Management.
Jan 2001C.Watters1 World Wide Web and E-Commerce Client Side Processing.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
Web Technologies Lecture 6 State preservation. Motivation How to keep user data while navigating on a website? – Authenticate only once – Store wish list.
PHP and Sessions. Session – a general definition The GENERAL definition of a session in the “COMPUTER WORLD” is: The interactions (requests and responses)
CSC 2720 Building Web Applications Basic Frameworks for Building Dynamic Web Sites / Web Applications.
ITM © Port,Kazman 1 ITM 352 Cookies. ITM © Port,Kazman 2 Problem… r How do you identify a particular user when they visit your site (or any.
1 PHP HTTP After this lecture, you should be able to know: How to create and process web forms with HTML and PHP. How to create and process web forms with.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
DT228/3 Web Development JSP: Actions elements and JSTL.
Unit-6 Handling Sessions and Cookies. Concept of Session Session values are store in server side not in user’s machine. A session is available as long.
Live. learn. work. play Superior Avenue Suite 310 Cleveland Ohio Tel: Fax:
Distributed Web Systems Cookies and Session Tracking Lecturer Department University.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
University of Kansas Department of Electrical Engineering and Computer Science Dr. Susan Gauch April 21, 2005 I T T C Introduction to Web Technologies.
Managing State Chapter 13.
ITM 352 Cookies.
Cookies BIS1523 – Lecture 23.
What is Cookie? Cookie is small information stored in text file on user’s hard drive by web server. This information is later used by web browser to retrieve.
Presentation transcript:

DT228/3 Web Development multi page applications/ sharing data

Introduction So far, have looked at examples with just a single JSP page Usually, will need more than one JSP page within the application Need to know how to 1) structure a JSP application 2) pass control from one JSP page to another 3) pass data from one JSP to another

Example A shopping application that accepts a users payment details on a form, validates the details and displays a confirmation page or error depending upon user input Various ways that JSP pages for collection of payment details can be structured. Can even have everything on a single JSP page (messy for anything but simplest apps) Have used 3 JSP pages: - payment details on a form(userinput.jsp) - validation of the details (validateinfo.jsp) - display of a confirmation page (confirmed.jsp) or error (userinput.jsp) depending upon user input

Userinput.jspinfovalidate.jsp Userinput.jsp Displays a form into which user enters their details Displays any errors on the form infovalidate.jsp Validates the info provided in userinput.jsp and passes back to userinput.jsp if there’s an error, or confirmed.jsp if info is valid. confirmed.jsp displays a message to user to confirm payment made. Example

Structure of JSP pages To determine how pages should be structured (e.g. one page vs more than one?): General guide: separate the presentation from the request processing and business logic. Presentation is the display of the application to the user I.e. the screens (e.g. display of the user input form, display of the confirmation message) Request processing and business logic is the ‘behind the scenes’ processing and manipulation (e.g. validation of user input) This is the basis of a common application architecture called the MVC (model-view-controller) architecture

This structure enables easier maintenance of the application. Presentation changes frequently (e.g web page enhancements) but business logic changes less often. Separation enables easier maintenance of presentation pages. May need multiple forms of presentation (e.g. to support multiple languages for international websites, to enable a variety of client devices) – easier to do if presentation is separate from business logic Structure of JSP pages

Userinput.jspinfovalidate.jsp Userinput.jsp Displays a form into which user enters their details infovalidate.jsp Validates the info provided in userinput.jsp and passes back to userinput.jsp if there’s an error, or confirmed.jsp if info is valid. confirmed.jsp displays a message to user to confirm payment made. Structure of JSP pages: example Presentation Request processing and business logic Presentation

Passing control from one page to another Separating presentation pages from request processing/business logic -  more than one page used to process client request ---  need to be able to pass control from one page to another ---  e.g. in the example, infovalidate.jsp need to be able to forward to either userinput.jsp or confirmed.jsp depending on validation result Can use the standard action tag

Passing control from one page to another has one attribute – “page” = target page e.g. Stops processing of one page and starts processing of the target page Target page has access to all request parameters from original page. Can also add additional request parameters when control passed, using action. action is nested within the jsp:forward action. It takes a name and value attribute.

Passing control from one page to another For example: A validation page (infovalidate.jsp) forward control to a page, userinput.jsp, in order to display an error message. Need to include error message in the the forwarding instruction. Name of parameter to be passed Value of parameter Target page

The target page in this example is assumed to be in the same directory on the web server as the current JSP page The target page in this example is assumed to be in the /somedir/ directory as a subset of the main application directory (../webapps/myapp/) Note: the tag is similar to the tag, but also allows redirection to a different URL. Passing control from one page to another

Sharing data across pages Often need to be able to share data across pages. For example, determine an error message in infovalidate.jsp and pass this to another page, confirmed. jsp Can use a core action to create a variable and save data to this variable. Can then access this variable in another part of the application. has various attributes (see page 44 of JSTL specification) including ‘var’, ‘value’ and ‘scope’ For example:

Previous example creates a variable called ‘errorMsg’, and sets its value to ‘Invalid entry’. The scope of the variable is ‘request’ When a JSP page needs to save data for its processing, it must specify the scope of the data The scope of a data object defines how long the data is available for (I.e. ‘how long it lasts’). Sharing data across pages : Scope

there are four Scopes available Page (I.e. only available within the JSP page. Page scoped data is destroyed when the page has finished generating its output.) Request ( I.e. available in all pages processing the same client request. Once the request from that has completed, the request-scope data is destroyed.) Session ( I.e. available to all requests made from the same user/client) Application ( I.e available to all users of that application, while the application is running)

To creates a variable that will be available to any JSP in the application: example: To retrieve the value of this variable in another JSP page: When retrieving a saved value, possible to omit the scope (as shown). If scope omitted, variable name is automatically searched for in each of the scopes, in the order: page, request, session, application Sharing data across pages : Scope

Userinput.jspinfovalidate.jsp Userinput.jsp Displays a form into which user enters their details Displays any errors on the form infovalidate.jsp Validates the info provided in userinput.jsp and passes back to userinput.jsp if there’s an error, or confirmed.jsp if info is valid. confirmed.jsp displays a message to user to confirm payment made. Sample code

userinput.jsp: displays a payment form. when the user clicks button, infovalidate.jsp is called. If an entry error is made, the infovalidate.jsp page forwards back to this with the error. Note: v. simple example for illustration. Details are not saved to a database or file.

confirmed.jsp: displays the confirmation. called by the infovalidate.jsp page if no errors

Sample code – user input.jsp Payment Form Need to know whether this is the first time form is displayed Check if there are any error messages to display. The’msg’ variable is set in the validation page

Sample code – user input.jsp (continued) Name: "> Credit card number: "> Display any previously enter values of username/credit card number

Sample code – infovalidate.jsp Username request parameter Must set scope to request. Otherwise, the message won’t be available to userinputinfo.jsp

Sample code – confirmed.jsp User Info Validated Your payment details are correct - thank you Note: This page is just template text (apart from comment) so could be created as a regular HTML file. Making it a JSP page allows dynamic content later without changing the referring page

Intro to Sessions  Many E-businesses personalise their customers’ browsing experiences by allowing for user preferences  Personalisation is done by tracking the users’ movement though the Internet and combining that info with data provided by the user (e.g. hobbies, address etc)  Robust web applications need to interact back and forth with the user, remembering information about the user between requests  Examples are CNN.com, MSN.com

Sessions  Session tracking is the ability to track a set of interactions between the client and the server  Request/response mechanism for web communication is based on HTTP  HTTP is a stateless protocol – it does not support persistent information  Web server cannot link requests with particular clients  The client needs to identify itself to the server in some way if the server is to recognise the client

Session tracking  Examples of session tracking information:  Shopping website: Items in a shopping cart: -> Item1, “Gone with the Wind”) ->Item2, “BeatlesCD”) -  Select these on one web page, check-out in a different part of the website. Web site “remembers” what you ordered by using session tracking  Web banking application: Bank employee selects the branch they are a member of. Session stores this info in some way: -> branch, “931012” Application “remembers” the branch number so that employee does not have to re-enter. Only customers relevant to the branch are shown throughout.

Session tracking  There are a number of different techniques available to web applications to enable session tracking, including cookies (next course).  In JSP, can be done by simply using the ‘scope’ attribute of whatever needs to be tracked.  Set the ‘scope’ to session, and the relevant attribute will be available throughout the entire session of the client  Example: a JSP page that displays two counters – a hit counter for the session, and a hit counter for the application

Session tracking header details etc <c:set var="sessionCounter" scope="session" value="${sessionCounter + 1}" /> <c:set var="applCounter" scope="application" value="${applCounter + 1}" /> Counter page This page has been visited times within the current session, and times by all users since the application was started. will last for the user’s session only will be updated by all users’ of the applicaton

Summary Looked at:  Structuring a JSP application  Passing control  Sharing data  Scope (page, request, session, application)  Session tracking