WebDev Essential Skills BCIS 3680 Enterprise Programming.

Slides:



Advertisements
Similar presentations
PHP II Interacting with Database Data. The whole idea of a database-driven website is to enable the content of the site to reside in a database, and to.
Advertisements

Cookies, Sessions. Server Side Includes You can insert the content of one file into another file before the server executes it, with the require() function.
1 Configuring Internet- related services (April 22, 2015) © Abdou Illia, Spring 2015.
Chapter 31 Basic Form-Processing Techniques JavaServer Pages By Xue Bai.
Servlets and a little bit of Web Services Russell Beale.
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
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.
Session Management A290/A590, Fall /25/2014.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
MS Access: Database Concepts Instructor: Vicki Weidler.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
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)
Chapter 4 – The Building Blocks Data Types Literals Variables Constants.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
Chapter 10 Managing Data with ASP.NET. ASP.NET 2.0, Third Edition2.
4-1 INTERNET DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
IT533 Lectures Session Management in ASP.NET. Session Tracking 2 Personalization Personalization makes it possible for e-businesses to communicate effectively.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
XP New Perspectives on Browser and Basics Tutorial 1 1 Browser and Basics Tutorial 1.
JavaScript, Fourth Edition
Advanced Web Forms with Databases Programming Right from the Start with Visual Basic.NET 1/e 13.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
Week 9 PHP Cookies and Session Introduction to JavaScript.
CSE 154 LECTURE 12: COOKIES. Including files: include include("filename"); PHP include("header.html"); include("shared-code.php"); PHP inserts the entire.
Tutorial 121 Creating a New Web Forms Page You will find that creating Web Forms is similar to creating traditional Windows applications in Visual Basic.
PHP meets MySQL.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
Chapter 8 Cookies And Security JavaScript, Third Edition.
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
PHP and MySQL CS How Web Site Architectures Work  User’s browser sends HTTP request.  The request may be a form where the action is to call PHP.
Session tracking There are a number of problems that arise from the fact that HTTP is a "stateless" protocol. In particular, when you are doing on- line.
Mark Dixon 1 03 – Passing Data between pages: Forms, Sessions, & Query Strings.
Website Development with PHP and MySQL Saving Data.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
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.
XHTML & Forms. PHP and the WWW PHP and HTML forms – Forms are the main way users can interact with your PHP scrip Typical usage of the form tag in HTML.
Web App GUI: JSP Basics & Forms 3680 Enterprise Programming.
® IBM Software Group © 2007 IBM Corporation Best Practices for Session Management
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.
CSCI 6962: Server-side Design and Programming Java Server Faces Scoping and Session Handling.
XP Tutorial 8 Adding Interactivity with ActionScript.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
Database Basics BCIS 3680 Enterprise Programming.
Database Access Using JDBC BCIS 3680 Enterprise Programming.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
1 State and Session Management HTTP is a stateless protocol – it has no memory of prior connections and cannot distinguish one request from another. The.
©SoftMooreSlide 1 Session Tracking with Servlets.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 1: Introduction to IS2803 Rob Gleasure
MIT AITI 2004 JSP – Lecture 4 Sessions and Cookies.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
8-Mar-16 More About Servlets Session Tracking. Persistent information A server site typically needs to maintain two kinds of persistent (remembered) information:
HTTP Transactions 1. 2 Client-Server Model 3 HTTP HyperText Transport Protocol Native protocol for WWW Sits on top of internet’s TCP/IP protocol HTTP.
PHP: Further Skills 02 By Trevor Adams. Topics covered Persistence What is it? Why do we need it? Basic Persistence Hidden form fields Query strings Cookies.
ISC440: Web Programming 2 Server-side Scripting PHP 3
Chapter 8 Working with Databases and MySQL
MashZone Dynamic data sources
Configuring Internet-related services
Web DB Programming: PHP
Presentation transcript:

WebDev Essential Skills BCIS 3680 Enterprise Programming

Overview 2  Getting and displaying information  Building SQL  Conversion or no conversion  Quotes or no quotes  Handling foreign key relationships  Shaping the retrieved info  Sharing and passing info among pages  Handcrafted query strings  Session variables  Application variables  Cookies

Building SQL 3  Information entered by user often is used to build a query, e.g., values for columns in an INSERT statement, filtering criterion in WHERE clauses, etc.  Remember that parameters are passed as Strings. Therefore:  For mandatory entries, read and store parameters as Strings.  For optional entries, first verify that the parameter is not null or empty strings.

No Conversion Needed 4  Since an SQL statement is essentially a long string and parameters are strings, we don’t have to convert a parameter value even if its business meaning is numeric because it is added to another string.  When building SQL statements, the operation involved is concatenation, not math!  For example, when building this WHERE clause: "WHERE price > " + request.getParameter("price");  We don’t have to convert the value of the price parameter by using Double.parseDouble() or Float.parseFloat() even though the price value may well be numeric.

To Quote or Not to Quote… 5  What needs to be decided is whether to concatenate a single quote before and after the parameter.  The business meaning of a parameter is a number, e.g., price, quantity, ID implemented as integers, etc.  No need to add single quotes when using it in filtering condition  The business meaning of a parameter is text, e.g., username, password, city, state, etc.  Need to add single quotes when using it in filtering condition (WHERE clauses).

No Quotes 6  If the business meaning of a parameter is numeric, and it looks like a number, then no single quotes are needed.  Build the SQL as a string until the numeric parameter value is needed. Then concatenate the parameter to it. String sql = "SELECT * FROM product WHERE id = " + request.getParameter("prodid");  So, if the product ID entered by the user is 1001, in runtime the variable sql will evaluate to: SELECT * FROM product WHERE prodid = 1001  If more string literals are needed as part of the SQL statement, concatenate them after the parameter.

Quotes 7  If the business meaning of a parameter is textual, then single quotes are needed.  Add an ' before concatenating the parameter and another one after the parameter.  Note in the example below that:  The second ' must be enclosed by two double-quotes ( "'"). String sql = "SELECT * FROM user WHERE username = '" + request.getParameter("username") + "'";  So, if the username entered by the user is Carlos, in runtime the variable sql will evaluate to: SELECT * FROM user WHERE username = 'Carlos'

What about the Semicolon 8  Although a semicolon is mandatory in MySQL to mark the end of an SQL statement, it is optional when the SQL statement is passed as the argument to the executeQuery() or executeUpdate() method of the Statement object.  However, some people find it helpful to add it so that it acts as an visual cue of the end of an SQL statement being built. That improves code readability. String sql = "SELECT * FROM user WHERE username = '" + request.getParameter("username") + "';"; String sql = "SELECT * FROM product WHERE id = " + request.getParameter("prodid") + ";";

Foreign Key Relationship 9  When building queries that retrieve information from two or more tables with foreign key relationship(s), it’s important that you “mimic” the FK relationship(s) in the WHERE clause by stating table1.FK = table2.PK ; the table names are mandatory to avoid ambiguity.  This must be repeated for every FK relationship between the tables.  Only the first one starts with the WHERE keyword; each subsequent part is added using the AND keyword.  If there is some filtering criterion, add it as the last AND (add additional AND s for additional criteria).

Repeating Table Rows 10  When multiple matches are returned by a query, usually they will be displayed in the same manner. That means there are some common HTML tags that will be used to enclose each result, e.g., the and tags.  Identify those HTML tags and situate them (as well as all the necessary out.print code) inside the loop body of while.  Leave HTML tags that are related but not supposed to be repeated (e.g., the and tags) outside of the loop.  If certain actions need to be performed on some but not all results, then add if statement(s) to do the job. The if statement still must be part of the loop body.

Shaping the Retrieved Info 11  Data are stored in DBMSes in their “raw” form (which conforms to the data types defined in the schema).  Thus, when retrieved, data often may not be in the exact form suitable for display in web pages.  Therefore, manipulation of the data after the query is returned often is needed before we mix them with HTML.  Useful String methods include:  substring()  replace()  indexOf()  charAt()

Shaping the Retrieved Info 12  There are some functions in SQL that performs some manipulations on the data. We can call them to get data that is represented more in line with the required format, e.g., use the YEAR function to retrieve just the year part of a date.  Such functions typically are for logical and mathematical operations. Their formatting capabilities are limited to say the best.  Using functions is not the optimal approach if the manipulation involved is too complex or if a number of transformations may be needed on the same set of data in the Web pages.

Sharing and Passing Info Among Pages 13  Handcrafted query string  Session variables  Application variables  Cookies

Handcrafted Query String 14  A is used to pass information from one page to the next. However, that takes place only when the submit button is clicked.  However, it’s often necessary to pass information through different channels, e.g., a hyperlink opens up another page and passes info to that new page because the latter is dynamic and needs that info from the current page.  It’d be very bad GUI design if the user had to click the submit button to open that hyperlink (the user’s intuitive action is to click the hyperlink to follow it).  In this scenario, we don’t want to rely on to pass information.

Handcrafted Query String 15  You can manually created a query string – a question mark followed by name-value pair(s), connected to each other by & s and append it to a URL.  In other words, the parameter name and value do not have to come from the name and value attributes of the tags. You may create them “out of the blue”.  However, this is a “quick and dirty” way that has limitations:  Just like using the tag, the parameters go only as far as the next page.  It works only when it does not generate security concerns because the parameters and their values are visible to the visitor.

request Does Not Travel Far 16  The most straightforward way to share information is the parameters in the request object.  However, parameters only travel as far as the next page. Going into the third page and you don’t see them.  The “sharing” is unidirectional – going forward to the next page. But often we need to go back and forward pages and still be able to access shared data.

request Does Not Travel Far 17

request Does Not Travel Far 18

A Dilemma in Web Design  HTTP is a stateless protocol.  The client makes a request; the server serves the requested document; and then the server closes the connection.  Each request from the client is processed independent of other requests.  The server does not “remember” previous requests from the same client.  This allows the server to serve a maximum number of concurrent requests efficiently.  However, there are many occasions when we want the server to “remember” the client, i.e., to maintain “state”.  We often need to share information among a number of pages in a Web application.

(Not Necessarily Good) Solutions  Sessions  Server-side collections of variables that make up the state.  Once logged on, the client is assigned a session ID.  Session variables do not survive browser closure – when the browser window is closed, the session is over.  Application  Information may be stored in the configuration file of a Web app.  Cookies  Small blocks of ASCII text stored on the client that can survive browser closures and computer reboots.  Web application cannot rely on the assumption that a user will accept cookies.

The Session Object 21  Implicit object, created automatically when a client requests a JSP page at the first time.  A session object is associated with all requests from within the same browser window.  Each client has a unique session object.  The session object can be accessed by its owner only.

Creating/Accessing Session Variables 22  To create a session variable, call the setAttribute() method of the session object: session.setAttribute("attributeName", anObjectReference);  To retrieve the value stored in a session variable later, call the getAttribute() method: session.getAttribute("attributeName");  To remove a session variable: session.removeAttibute("attributeNameToRemove");

Session Variables 23

Session Variables 24

Web Applications 25  A Web application is a group of files  A Web application software provides services to a variety of clients  It consists of the following components:  Web server  Documents  Application server

The Application Object 26  Each Web application has one and only one application object.  The application object can be shared by all application users.  It can be used to hold references to other objects that can be accessed by all users.

Application Variables 27  Accessible to all clients.  Can be initialized when you configure the Web server and/or the Web application.  Can be created by using the application object in a JSP file.

Application Variables 28

Initialization Parameters 29  Set initialization parameters in web.xml (you need to restart Web server) variable name value For example: webmaster

Get Initialization Parameters 30  Accessible from any JSP file under the same application application.getInitParameter("parameterName")  Returns a string containing the value of the named parameter  If the parameter does not exist, it returns a null value application.getInitParameterNames()  Returns the names of these initialization parameters as an enumeration of string objects

Setting/Getting App Variables in Code 31  You may create new application variables in code (instead of in the configuration file): application.setAttribute("attr_name", an_object)  This method binds an object to a given attribute name  When you use the setAttribute() method to set an attribute, if the name specified is already used for an attribute, this method removes the old bound object and binds the name to the new object.

Remove Application Variable 32  To access the value stored in the application variable later: application.getAttribute("attribute_name")  This method returns an object bound to the attribute with the given name; if there is no attribute by that name, it returns a null value.  To remove an application variable: application.removeAttribute("attributeName");  This method removes the attribute with the given name. After removal, subsequent calls to getAttribute("attributeName") to retrieve the attribute's value will return null.