CS411-Proj-Web_Programming

CS411-Proj-Web_Programming - CS411: Database Systems:: Term...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS411: Database Systems:: Term Project Introduction to Web Programming September 27, 2011 Reza Shiftehfar PhD. Student and Research Assistant in Computer Science Dept. of Computer Science University of Illinois at Urbana Champaign E­mail: sshifte2@illinois.edu CS411 Course Project Track 1 Announcements: Assignment 2 is available. Please check the assignment page Thursday 29th is the due date for Project 2, Stage 1. This is specifically for graduate students who registered for the course for 4 credit­hours Fill out the survey: There are questions about the project Track 1 and the Database and Web tutorial sessions Please fill them now and return them to me We will use these feedbacks to improve the class. 2 CS411 Course Project Track 1 Still looking for project? We are working on a Disaster Management Project Using Cell phone to: Find Location in indoor areas (Positioning) Find the activity (Activity Recognition) It is Android based and requires server­side development Funding will probably be available May even extend beyond this semester Ø If you are interested, come and see me after lecture or send me email at sshifte2@illinois.edu 3 CS411 Course Project Part 1: Web development 4 CS411 Course Project Track 1 What is Web Development: Web development is a broad term for any activity re­ lated to developing a web site for the World Wide Web or the Intranet. Usually refers to the non­design aspects of building a website: writing markup and coding It ranges from creation of a simple static html page to the most complex web­based internet application or so­ cial network service 5 CS411 Course Project Track 1 The objective of this lecture: To give you a very high­level overview of some of the tools for Web Programming Use several typical tools to show the basics of Web Programming Not meant for advanced Web developers We will assume minimal interaction with DBMS in this lecture to focus on the Web programming part 6 CS411 Course Project Track 1 Web Programming: Web Programming can be di­ vided in two sides: Client programming Server Programming Client Client Presentation Server Internet Logic Data 7 CS411 Course Project Track 1 Client Side Programming: Code that runs on the client side’s browser. HTML Ø stands for HyperText Markup Language Ø predominant markup language for web pages. Ø Written in the form of HTML elements consisting of "tags" surrounded by angle brackets within the web page content Javascript Ø Javascript is a ubiquitous client side programming 8 CS411 Course Project Track 1 Client Side Coding: Applet and ActiveX. Ø small application that performs one specific task and runs within a larger program Ø Ø perhaps as a plug­in. E.g. Java Applet running on web pages AJAX (Asynchronous Javascript And XML) Ø Group of interrelated web development method Ø used on the client­side 9 CS411 Course Project Track 1 Server Side Coding: Code that runs on the server side: CGI: standard protocol for server­client communication PHP: open source ASP.NET: Microsoft proprietary JSP: JavaServer Pages Python, e.g. Django web framework, open source Ruby, e.g. Ruby on Rails, open source 10 CS411 Course Project Track 1 LAMP:: Open Source Solution: Bundle of Software Linux: referring to the operating system; Apache: the Web server; MySQL: the database management system (or data­ base server); PHP or others, i.e., Perl, Python: the programming lan­ guages LAMP is: easy to code locally and deploy 11 CS411 Course Project Track 1 Plan of the lecture: Client Programming: Ø HTML Ø Javascript Server Side programming: Ø PHP (as in the LAMP architecture) Additional tools: Ø Ajax Some Demos 12 CS411 Course Project Part 2: Client Side Programming 13 CS411 Course Project Track 1 HTML:: representing data with HTML HTML is a language for describing web pages. HTML stands for Hyper Text Markup Language HTML is not a programming language it is a markup language A markup language is a set of markup tags HTML uses markup tags to describe web pages 14 CS411 Course Project Track 1 HTML:: Basics 1. <h1> This is a heading </h1> 2. <a href="http://www.illinois.edu"> This is a link </a> 3. <img src="w3schools.jpg" width="104" height="142" /> 4. <form> First name: 5. 6. </form> <input type="text" name="firstname" /> 15 CS411 Course Project Track 1 HTML:: Creating a simple html file at projects.cs.illinois.edu Go to your project page management site: http://accounts.cs.illinois.edu/projects Web pages created here will appear at: http://netid.cs.projects.illinois.edu Let’s create a HTML hello world: 1. <HTML> 2. <HEAD> 3. <TITLE> 4. A Small Hello 16 CS411 Course Project Track 1 HTML:: Creating a simple html file at projects.cs.illinois.edu 7. 8. 9. <BODY> <H1> Hi </H1> <P>This is "hello world" HTML document.</P> 10. </BODY> 11. </HTML> Place a blank or “hello world” page called “test.html" and make sure that you can access it at: http://netid.projects.cs.illinois.edu/test.html Replace “netid” with your netid. 17 CS411 Course Project Track 1 JavaScript:: JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language. JavaScript is usually embedded directly into HTML pages JavaScript is an interpreted language (means that scripts execute without preliminary compilation) 18 CS411 Course Project Track 1 JavaScript:: The HTML <script> tag is used to insert a JavaScript into an HTML page. <html> <body> <script type="text/javascript"> document.write("Hello World!"); </script> </body> </html> 19 CS411 Course Project Track 1 JavaScript:: What it can do for you? JavaScript can put dynamic text into an HTML page A JavaScript statement like this: Ø document.write("<h1>" + name + "</h1>") Ø can write a variable text into an HTML page JavaScript can react to events Ø A JavaScript can be set to execute when something happens Ø E.g. when a page has finished loading or when a user clicks on an HTML element 20 CS411 Course Project Track 1 JavaScript:: What it can do for you? JavaScript can read and write HTML elements Ø A JavaScript can read and change the content of an HTML element JavaScript can be used to validate data Ø A JavaScript can be used to validate form data be­ fore it is submitted to a server. Ø This saves the server from extra processing 21 CS411 Course Project Track 1 JavaScript:: Demo Demo for HTML: Ø http://sshifte2.projects.cs.illinois.edu/demo1.html Demo for JavaScript: Ø http://sshifte2.projects.cs.illinois.edu/demo2.html 22 CS411 Course Project Part 3: Server Side Programming 23 CS411 Course Project Track 1 PHP:: What is PHP general­purpose server­side scripting language It is: open source, server­side, HTML embedded script­ ing language used to create dynamic Web pages. PHP files can contain text, HTML tags and scripts PHP files are returned to the browser as plain HTML PHP files have file extension of ".php", ".php3", or ".phtml” Contrast with Javascript, which is client­side, PHP is 24 CS411 Course Project Track 1 PHP:: Hello World: Example of a simple HTML + PHP script which sends the text "Hello World" to the browser: <html> <body> <?php echo "Hello World!; ?> </body> </html> 25 CS411 Course Project Track 1 PHP:: Basics: A PHP file normally contains HTML tags, just like an HTML file, and some PHP scripting code A PHP scripting block always starts with <?php and ends with ?>. A PHP scripting block can be placed anywhere in the document. All variables in PHP start with a $ sign symbol. Ø $var_name = value; A type does not need to be specified in advance. 26 CS411 Course Project Track 1 PHP:: Basics: Numeric array An array with a numeric index $cars=array("Saab“,"Volvo","BMW","Toyota"); $cars[0]="Saab"; $cars[1]="Volvo"; $cars[2]="BMW"; $cars[3]="Toyota"; 27 CS411 Course Project Track 1 PHP:: Basics: Associated Arrays: syntax is: array(key => value), so create key­value pairs: Ø <?php $a=array("a"=>"Dog","b"=>"Cat","c"=>"Horse"); print_r($a); ?> Ø output: Array ( [a] => Dog [b] => Cat [c] => Horse ) 28 CS411 Course Project Track 1 PHP:: Basics: Multidimensional Arrays: Ø $families = array ( “TA"=> array (“Reza", “Mark", “Duo"), “Instructor"=>array (“Peixiang“, “Yizhou”), “Students"=>array(“David", “John", “Lisa") ); 29 CS411 Course Project Track 1 PHP:: Basics: if (condition) code to be executed if condition is true; for (init; condition; increment) { } code to be executed; function functionName() { code to be executed; } 30 CS411 Course Project Track 1 PHP:: Get User Input with GET and POST: $_GET[“var”]: Sending values to the PHP pahe using the URL: Ø e.g. after submitting a form, the code will look like: Ø http://www.w3schools.com/welcome.php? fname=Peter&age=37 Ø The "welcome.php" file can now use the $_GET function to collect form data Ø Welcome <?php echo $_GET["fname"]; ?> Ø output: Displays “Welcome Peter” 31 CS411 Course Project Track 1 PHP:: Track Http State: Http is a stateless protocol. It does not require the server to retain information or status about each user for the duration of multiple re­ quests. The web application may have to track the user's pro­ gress from page to page. Ø e.g., user login, items in a cart Solution: 32 CS411 Course Project Track 1 PHP:: Using Cookies in PHP: A cookie is often used to identify a user small file that the server embeds on the user's com­ puter. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie val­ ues create a cookie: 33 CS411 Course Project Track 1 PHP:: Using Session in PHP: A PHP session variable is used to store information about settings for a user session. Session variables hold information about one single user, and are available to all pages in one application. session_start() creates a session or resumes the cur­ rent one based on a session identifier passed via a GET or POST request, or passed via a cookie. To store and retrieve session variables, use the PHP $_SESSION variable 34 CS411 Course Project Track 1 PHP:: Cookie vs. Session: Cookie Ø More permanent Ø Typically small (need to be sent to server) Session Ø Typically in server memory (ends when you close browser) Ø Can be of any size 35 CS411 Course Project Track 1 PHP:: Demo: Hello World PHP: http://sshifte2.projects.cs.illinois.edu/demo3.php A more complicated example in PHP: http://sshifte2.projects.cs.illinois.edu/demo4.php 36 CS411 Course Project Track 1 Ajax: Asynchronous JavaScript and XML a group of interrelated web development techniques used to create interactive web applications or rich In­ ternet applications. AJAX allows web pages to be updated asynchronously by exchanging small amounts of data with the server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page. 37 CS411 Course Project Track 1 Ajax: Ajax is based on Internet Standards AJAX is based on internet standards, and uses a com­ bination of: Ø XMLHttpRequest object Ø Ø to exchange data asynchronously with a server JavaScript/DOM Ø to display/interact with the information on client side Ø CSS 38 CS411 Course Project Track 1 Ajax: Ajax Suggestion Example Example: Google search suggestion It is using AJAX to create a dynamic web interface When you start typing in Google's search box, a JavaScript sends the letters off to a server and the server returns a list of suggestions. Note that the page does not reload as you type 39 CS411 Course Project Track 1 ASP.NET and JSP: They follow pretty similar architecture ASP.net: Ø server side scripting technology that enables scripts (embedded in web pages) to be executed by an In­ ternet server. Ø normally used together with SQLServer (MS propri­ etary) JSP: 40 CS411 Course Project Track 1 Other tools for Web Programming: Django: Ø open source web application framework written in Python Ø emphasizes reusability and "pluggability" of com­ ponents, rapid development Ruby on Rails: Ø open source web application framework for the Ruby programming language Ø 41 CS411 Course Project Track 1 Take Away Message: Web Programming is not hard but it takes time to learn basics and fix bugs Choose your preferred tools early, and start to get famil­ iar with them Many tutorials (with examples) available on the web W3Schools is a great place to start: http:// www.w3schools.com 42 CS411 Course Project Track 1 References: Getting starting with CGI Programming in C Ø http://www.cs.tut.fi/~jkorpela/forms/cgic.html PHP related examples, including PHP + MySQL http://www.w3schools.com/php/ Ø W3Schools tutorials are generally very helpful, on almost all the tools we covered Also for using PHP with MySQL: Ø Hugh Williams and David Lane, ``Web Database Applications with PHP and MySQL'' 43 ...
View Full Document

Ask a homework question - tutors are online