Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html 1 of 74 4/2/2008 12:14 PM Table of Contents | All Slides | Link List | CSCI E-12 Web 2.0, Ajax, Dynamic Sites April 2, 2008 Harvard University Division of Continuing Education Extension School Course Web Site: http://cscie12.dce.harvard.edu/ Copyright 1998-2008 David P. Heitmeyer Instructor email: [email protected]Course staff email: [email protected]Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html 2 of 74 4/2/2008 12:14 PM Web 2.0 Suggested readings for Web 2.0: What Is Web 2.0: Design Patterns and Business Models for the Next Generation of Software by Tim O'Reilly Web 2.0, article from Wikipedia What is Web 2.0? Not a technical standard or technology Web 2.0 does have characteristics and features There are some technologies commonly found in Web 2.0
37
Embed
Web 2.0, Ajax, Dynamic Sites · Mutliple Filter Criteria with Ajax We create an interface that allows schools to be filtered by Division Conference School Pulldown menus created through
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
1 of 74 4/2/2008 12:14 PM
Table of Contents | All Slides | Link List | CSCI E-12
Web 2.0, Ajax, Dynamic SitesApril 2, 2008
Harvard University Division of Continuing Education
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
2 of 74 4/2/2008 12:14 PM
Web 2.0
Suggested readings for Web 2.0:
What Is Web 2.0: Design Patterns and Business Models for the Next Generation of Software byTim O'Reilly
Web 2.0, article from Wikipedia
What is Web 2.0?
Not a technical standard or technology
Web 2.0 does have characteristics and features
There are some technologies commonly found in Web 2.0
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
3 of 74 4/2/2008 12:14 PM
Web 2.0 Features and Characteristics
What Is Web 2.0: Design Patterns and Business Models for the Next Generation of Software by TimO'Reilly
Principles, Characteristics, Features:
Services, not packaged software, with cost-effective scalability
Control over unique, hard-to-recreate data sources that get richer as more people use them
Amazon
Trusting users as co-developers
Harnessing collective intelligence
Wikipedia
Leveraging the long tail through customer self-service
Google AdSense
Software above the level of a single device
Lightweight user interfaces, development models, AND business models
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
4 of 74 4/2/2008 12:14 PM
Web 2.0 in Images
User-contributed data (active and passive)
Mashups - combining, remixing data
External Services and Functionality
Rich User Interfaces and Rich Internet Applications
Web 2.0 Meme Map by Tim O'Reilly
Visualizing Web 2.0 by Dion Hinchcliffe
Visualizing Web 2.0, Peter, blog.forret.com
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
5 of 74 4/2/2008 12:14 PM
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
6 of 74 4/2/2008 12:14 PM
Web 2.0 Examples
Zillow
www.zillow.com
Housingmaps.com
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
7 of 74 4/2/2008 12:14 PM
www.housingmaps.com
ChicagoCrime.org
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
8 of 74 4/2/2008 12:14 PM
www.chicagocrime.org
Del.icio.us
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
9 of 74 4/2/2008 12:14 PM
del.icio.us
Flickr
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
10 of 74 4/2/2008 12:14 PM
flickr.com
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
11 of 74 4/2/2008 12:14 PM
Encyclopedia of Life
Encyclopedia of Life, www.eol.org
WASHINGTON (May 9, 2007) – Many of the world’s leading scientific institutions today announced the launchof the Encyclopedia of Life, an unprecedented global effort to document all 1.8 million named species ofanimals, plants, and other forms of life on Earth. For the first time in the history of the planet, scientists,students, and citizens will have multi-media access to all known living species, even those that have just beendiscovered. more
6 cornerstone institutions
9 data partners (and growing)
thousands of "curators"
tens (hundreds or more?) of thousands of potential contributors
Falco peregrinus (Peregrine Falcon)
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
12 of 74 4/2/2008 12:14 PM
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
24 of 74 4/2/2008 12:14 PM
Conferences: JSON
Instead of returning HTML to be put into the page, our server-side process will return JSON (JavaScriptObject Notation). We can then process the JSON data into the page.
function load() { 1. if (GBrowserIsCompatible()) { 2. var map = new GMap2(document.getElementById("map")); 3. map.addControl(new GSmallMapControl()); 4. map.addControl(new GMapTypeControl()); 5. map.addControl(new GOverviewMapControl()); 6. map.setCenter(new GLatLng(41,-74), 6); 7. map.setMapType(G_MAP_TYPE); 8. // Download the data in data.xml and load it on the map. The format we 9. GDownloadUrl("ivy.xml", function(data) { 10. var xml = GXml.parse(data); 11. var markers = xml.documentElement.getElementsByTagName("marker"); 12. for (var i = 0; i < markers.length; i++) { 13. var elem = markers[i]; 14. var point = new GLatLng(parseFloat(elem.getAttribute("lat")), 15. parseFloat(elem.getAttribute("lng"))); 16. gmarker = createMarker(point,elem); 17. map.addOverlay(gmarker); 18. } 19. }); 20. } 21.} 22.function createMarker(point,elem) { 23. var gmarker = new GMarker(point); 24. var label = elem.getAttribute("label"); 25. GEvent.addListener(gmarker, "click", function() { 26. gmarker.openInfoWindow(label); 27. }); 28. return gmarker; 29.} 30.
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
32 of 74 4/2/2008 12:14 PM
Google Maps: CSCI E-12
Javascript Application that uses Ajax to pull in map marker data.
Load Google Map JS from Google
Provide our data through Ajax
Create "markers" for map according to Google Map API
Place "markers" and information on maps via XML data.
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
33 of 74 4/2/2008 12:14 PM
Marker Data
campus_data_spring2008.xml
Javascript createMarker function:
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
34 of 74 4/2/2008 12:14 PM
view plain print ?
function createMarker(point, elem) { 1. // create tabs 2. var infoTabs = []; 3. var tabs = elem.getElementsByTagName("tab"); 4. for (var i = 0; i < tabs.length; i++) { 5. var tab = new GInfoWindowTab( 6. tabs[i].getAttribute("label"), 7. tabs[i].getElementsByTagName("content")[0].textContent 8. ); 9. infoTabs.push(tab); 10. } 11. // create marker, add tabs 12. var marker = new GMarker(point); 13. GEvent.addListener(marker, "click", function() { 14. marker.openInfoWindowTabsHtml(infoTabs); 15. }); 16. return marker; 17.} 18. 19.// load function 20.function load() { 21. if (GBrowserIsCompatible()) { 22. var map = new GMap2(document.getElementById("map")); 23. // configure map properties 24. map.addControl(new GSmallMapControl()); 25. map.addControl(new GMapTypeControl()); 26. map.addControl(new GOverviewMapControl()); 27. map.setCenter(new GLatLng(42.375492,-71.117613), 16); 28. map.setMapType(G_HYBRID_TYPE); 29. // Download the data in data.xml and load it on the map. 30. GDownloadUrl("campus_data.xml", function(data) { 31. var xml = GXml.parse(data); 32. var markers = xml.documentElement.getElementsByTagName("marker"); 33. /* iterate through "marker" data, creating 34. for each a Google Map Marker */ 35. for (var i = 0; i < markers.length; i++) { 36. var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")), 37. parseFloat(markers[i].getAttribute("lng"))); 38. var marker = createMarker(point, markers[i]); 39. map.addOverlay(marker); 40. } 41. }); 42. } 43.} 44.
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
35 of 74 4/2/2008 12:14 PM
JavaScript Applications
The SIMILE project from MIT has some great examples of JS applications
Exhibit
Timeline
US Congress and Exhibit
Provide the data and the template, and Exhibit provides the functionality: different views, timelineaccording to birth date, filtering, sorting, and grouping.
Congress Exhibit Template
Congress People Data (JSON)
Tiles View
Table View (columns are sortable)
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
46 of 74 4/2/2008 12:14 PM
"XHTML with Programs" Examples
Examples include: SSI, PHP, JSP, ASP, some Perl template systems
JSP example:
view plain print ?
<html> 1. <body> 2. <h1> Some dynamic content using JSP:</h1> 3. <ul> 4. <li><strong>Expression.</strong><br> Your hostname: 5. <%= request.getRemoteHost() %> 6. <li><strong>Scriptlet.</strong><br/> 7. <% out.println("Attached GET data: " + request.getQueryString()); %> 8. <li><strong>Declaration (plus 9. expression).</strong><br/> 10. <%! private int accessCount = 0; %> 11. Accesses to page since server restart: 12. <%= ++accessCount %> 13. <li><strong>Directive (plus expression).</strong><br/> 14. <%@ page import = "java.util.*" %> 15. Current date: <%= new Date() %> 16. </ul> 17. </body> 18.</html> 19.
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
47 of 74 4/2/2008 12:14 PM
PHP: Hypertext Processor
PHP: Hypertext Processor
From the PHP manual:
PHP, which stands for "PHP: Hypertext Preprocessor" is a widely-used Open Source general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. Its syntax draws upon C, Java, and Perl, and is easy to learn. The main goal of the language is to allow web developers to write dynamically generated web pages quickly, but you can do much more withPHP.
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
48 of 74 4/2/2008 12:14 PM
Model, View, Controller (MVC) Design Pattern
MVC design pattern separates:
Model. data model
View. user interface
Controller. control and flow logic
You can adopt this design pattern regardless of language or server-architecture (CGI, internal process,external process). Some frameworks make using MVC possible, some hard, some easy, some insiston it.
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
49 of 74 4/2/2008 12:14 PM
Java Expression Language (EL)
e.g.ivy/list.html
Template uses an "expression" language to produce content, not Java. There is a Java process("Controller" and "Model") that gets the data, and then forwards the data to the "View" component for processing on the server before it is sent to the browser.
In this example, an array of "schools" is available to the view. The schools are essentially a map thatcould be represented like:
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
50 of 74 4/2/2008 12:14 PM
Producing a Different View
e.g.ivy/seals.html
Based upon the URL pattern, the "Controller" can call a different view. The "Model" provides the samedata in this case. Our template produces a display of the schools' seals.
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
51 of 74 4/2/2008 12:14 PM
EL to Produce Data for Google Maps
e.g.ivy/markers.xml
Here we use a different template to produce "marker" data for Google Maps. Note that the data sent isthe same ("Model" is doing the same thing). The "Controller" would be calling a different view basedupon a URL pattern.
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
66 of 74 4/2/2008 12:14 PM
FAS Course Data
Course data for Faculty of Arts & Sciences is in a mysql database on minerva (username: class; database name: coursecatalog)
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
67 of 74 4/2/2008 12:14 PM
view plain print ?
minerva$ mysql -u class coursecatalog 1.Reading table information for completion of table and column names 2.You can turn off this feature to get a quicker startup with -A 3. 4.Welcome to the MySQL monitor. Commands end with ; or \g. 5.Your MySQL connection id is 515 to server version: 3.23.58 6. 7.Type 'help;' or '\h' for help. Type '\c' to clear the buffer. 8. 9.mysql> describe courses; 10.+------------------------------+--------------+------+-----+---------+-------+ 11.| Field | Type | Null | Key | Default | Extra | 12.+------------------------------+--------------+------+-----+---------+-------+ 13.| acad_year | year(4) | YES | | NULL | | 14.| cat_num | int(9) | YES | | NULL | | 15.| offered | char(1) | YES | | NULL | | 16.| department_code | varchar(15) | YES | | NULL | | 17.| department_short | varchar(80) | YES | | NULL | | 18.| department_long | varchar(200) | YES | | NULL | | 19.| course_group_code | varchar(10) | YES | | NULL | | 20.| course_group_long | varchar(200) | YES | | NULL | | 21.| num_int | int(9) | YES | | NULL | | 22.| num_char | varchar(15) | YES | | NULL | | 23.| term_pattern_code | int(5) | YES | | NULL | | 24.| fall_term | char(1) | YES | | NULL | | 25.| spring_term | char(1) | YES | | NULL | | 26.| term | varchar(100) | YES | | NULL | | 27.| title | text | YES | | NULL | | 28.| course_type | varchar(100) | YES | | NULL | | 29.| course_level_code | char(1) | YES | | NULL | | 30.| course_level | varchar(200) | YES | | NULL | | 31.| credit_code | int(5) | YES | | NULL | | 32.| credit | varchar(50) | YES | | NULL | | 33.| instructor_approval_required | char(1) | YES | | NULL | | 34.| meeting_time | text | YES | | NULL | | 35.| faculty_text | text | YES | | NULL | | 36.| description | text | YES | | NULL | | 37.| prerequisites | text | YES | | NULL | | 38.| notes | text | YES | | NULL | | 39.+------------------------------+--------------+------+-----+---------+-------+ 40.26 rows in set (0.00 sec) 41. 42.mysql> select distinct department_short from courses; 43.+----------------------------------------------------------+ 44.| department_short | 45.+----------------------------------------------------------+ 46.| African and African American Studies | 47.| Anthropology | 48.| Architecture, Landscape Architecture, and Urban Planning | 49.| Asian Studies Program | 50.| Astronomy | 51.| Biological Sciences in Dental Medicine | 52.| Biological Sciences in Public Health | 53.| Biophysics | 54.| Biostatistics | 55.| Celtic Languages and Literatures | 56.| Chemical Biology | 57.| Chemical and Physical Biology | 58.| Chemistry | 59.| Comparative Literature | 60.| Core Curriculum | 61.| Dramatic Arts | 62.| Earth and Planetary Sciences | 63.| East Asian Languages and Civilizations | 64.| Economics | 65.| Engineering and Applied Sciences | 66.| English and American Literature and Language | 67.| Environmental Science and Public Policy | 68.| Expository Writing | 69.| Folklore and Mythology | 70.| Freshman Seminars | 71.| Germanic Languages and Literatures | 72.| Government | 73.| Health Policy | 74.| History | 75.
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
68 of 74 4/2/2008 12:14 PM
Web 2.0, Ajax, Dynamic Sites http://localhost:8080/cocoon/projects/cscie12/slides/20080402/handout.html
69 of 74 4/2/2008 12:14 PM
Mixing of Concerns instead of SOC
Mixing of concerns instead of SOC.This particular example is with PHP, but you can easily achieve "entangling of concerns" with Java(JSP), ASP, Python, or Perl. The problem is not with the language, but with the structure.