Bin Fu 03/27/2012 15-415 Spring 2012 Homework 7 Building A Web Application School of Computer Science.

Slides:



Advertisements
Similar presentations
Chapter 6 Server-side Programming: Java Servlets
Advertisements

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Using Perl for CGI Programming.
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
DT228/3 Web Development WWW and Client server model.
Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Database Design Methodology handout.
Java, Access, SQL, HTML. Three-tier architecture involves: Client - Browser Server - Tomcat Database - Access - Server-side language - JSP could just.
Servlets and a little bit of Web Services Russell Beale.
1 Active Server Pages Active Server Pages (ASPs) are Web pages ASP = server-side scripts + HTML The appearance of an Active Server Page depends on who.
1 Java Server Pages Can web pages be created specially for each user? What part does Java play?
Three types of scripting elements: 1.Expressions 2.Scriptlets 3.Declarations Scripting elements.
CMPUT 391 – Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems JavaServer Pages (JSP)
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Struts 2.0 an Overview ( )
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
Chapter 9 Using Perl for CGI Programming. Computation is required to support sophisticated web applications Computation can be done by the server or the.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
CSCI 6962: Server-side Design and Programming Course Introduction and Overview.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
4-1 INTERNET DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
3/8/00asp00 1 Active Server Pages from Microsoft Nancy McCracken Northeast Parallel Architectures Center at Syracuse.
Lecture 7 Interaction. Topics Implementing data flows An internet solution Transactions in MySQL 4-tier systems – business rule/presentation separation.
JSP Java Server Pages Softsmith Infotech.
Chapter 7 Java Server Pages. Objectives Explain how the separation of concerns principle applies to JSP Describe the operation and life-cycle of a JSP.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
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.
School of Computing and Information Systems CS 371 Web Application Programming PHP – Forms, Cookies, Sessions and Database.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
Implementation - Part 2 CPS 181s March 18, Pieces of the Site-building Puzzle Page 180, figure 4.1.
Domain Driven Web Development With WebJinn Sergei Kojarski College of Computer & Information Science Northeastern University joint work with David H. Lorenz.
Chapter 6 Server-side Programming: Java Servlets
DAT602 Database Application Development Lecture 16 Java Server Pages Part 2.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
Domain Driven Web Development With WebJinn Sergei Kojarski College of Computer & Information Science Northeastern University joint work with David H. Lorenz.
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.
Leman Akoglu 11/11/ Fall 2009 Recitation Homework 9 Building A Web Application Phase-II School of Computer Science.
CSE 154 LECTURE 5: INTRO TO PHP. URLs and web servers usually when you type a URL in your browser: your computer looks up the.
Controlling Web Site Access Using Logins CS 320. Basic Approach HTML form a php page that collects the username and password  Sends them to second PHP.
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
CITA 310 Section 7 Installing and Testing a Programming Environment (Textbook Chapter 7)
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.
Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server 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.
WEB SERVER SOFTWARE FEATURE SETS
Vakgroep Informatietechnologie – Onderzoeksgroep (naam) Web Centric Design of Distributed Software.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Servers- Apache Tomcat Server Server-side scripts- Java Server Pages.
Higher Computing Science Coding the Web: HTML, JavaScript, PHP and MySQL.
Chapter 6 Chapter 6 Server Side Programming (JSP) Part 1 1 (IS 203) WebProgramming (IS 203) Web Programming.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Bayu Priyambadha, S.Kom. Static content  Web Server delivers contents of a file (html) 1. Browser sends request to Web Server 3. Web Server sends HTML.
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing.
World Wide Web has been created to share the text document across the world. In static web pages the requesting user has no ability to interact with the.
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.
Java Server Pages Can web pages be created specially for each user?
JSP Based on
Web Development Web Servers.
15-415/615 Spring 2013 Homework 7 Building A Web Application
PHP / MySQL Introduction
HW7: Database Application
Lecture #19 (not in book) Database Design Methodology handout
School of Computer Science
Tutorial 10: Programming with javascript
Presentation transcript:

Bin Fu 03/27/ Spring 2012 Homework 7 Building A Web Application School of Computer Science

HW7 Outline Building a simple Web application (“Twitter”) using JSP 2 phases Phase I : design and documentation due 4/3 hard copy in class Phase II : implementation due 4/12 both hard copy in class and via . Start early!

description req. anal. top level I.F.D.sys. anal. conc. mod. impl.+test. task + doc forms.schema. code. task emul. tests user’s man. pseudo-code Phase-IPhase-II Database Design Methodology [N. Roussopoulos and R.T. Yeh]

Office Hours for HW7 3/28 (Wed) 12pm – 3pm 3/30 (Fri) 1pm – 2pm 4/2 (Mon) 12pm – 3pm 4/3 4/4 (Wed) 12pm – 3pm 4/5 (Thu) 3pm – 6pm 4/6 (Fri) 1pm – 2pm 4/9 (Mon) 12pm – 3pm 4/10 (Tue) 3pm – 6pm 4/12 Phase-1 Phase-2  Send additional questions to Phase-1 due Phase-2 due

description req. anal. top level I.F.D.sys. anal. conc. mod. impl.+test. task + doc forms.schema. code. task emul. tests user’s man. pseudo-code Phase-IPhase-II

Homework 7 A micro-blog web application like Twitter Users could add tweet, follow other’s tweet, etc. Tasks to implement 1. Registration (a simple example is already provided) 2. Login/Logout 3. Profile Page 4. Add Tweet 5. Browse Tweet 6. “Follow” Management 7. Hashtag Search 8. Reporting (website statistics)

description req. anal. top level I.F.D.sys. anal. conc. mod. impl.+test. task + doc forms.schema. code. task emul. tests user’s man. pseudo-code Phase-IPhase-II

registration form T1-reg. user record Top level information flow diagram (Homework I.1) System boundary tasks internal document (database tables) external document (web forms)

registration form More on top level diagram login form T2 - login ? T1-reg. user record ? profile page

description req. anal. top level I.F.D.sys. anal. conc. mod. impl.+test. task + doc forms.schema. code. task emul. tests user’s man. pseudo-code Phase-IPhase-II

Document + Task forms Task forms and task list not required for this homework Document forms and document list D1: registration form D2: login form D3: profile form … Dx: user record … internal external

Document forms (Homework I.2-3) D1: registration form login name password name D3: profile form login name? … List-of: tweet owner (login name) ? … Dx: user record login name password name

description req. anal. top level I.F.D.sys. anal. conc. mod. impl.+test. task + doc forms.schema. code. task emul. tests user’s man. pseudo-code Phase-IPhase-II

E-R diagram (Homework I.4-6) user tweet login URL... passw How about follows, tags …? o Specify cardinalities o Think about weak/strong entities own ??

Relational schema (Homework I.7-8) user( login, passw, … ) tweet( owner, content … ) ? …. SQL DDL statements (Homework I.9) create table users (login char(20), passwd char (20) NOT NULL (?), … ); create table tweet (content char(140), … );...

description req. anal. top level I.F.D.sys. anal. conc. mod. impl.+test. task + doc forms.schema. code. task emul. tests user’s man. pseudo-code Phase-IPhase-II

Task emulation/pseudo-code (Homework I.10) Task1: Registration read login, password and if ( login does not exist in ‘user’){ insert into user values (login_id, password, ); } else{ print “error: login exists, choose another” } should be valid SQL queries

description req. anal. top level I.F.D.sys. anal. conc. mod. impl.+test. task + doc forms.schema. code. task emul. tests user’s man. pseudo-code Phase-IPhase-II

Phase II You will develop JSP pages that handle user interactions Processing logic written in Java class Manipulating data in database, connect from JSP to database using JDBC

Users Web app (JSP, ASP, PHP) Apache, Tomcat, Windows IIS Web Server Java Virtual Machine Web app backend component Backend Server Database Server Client Web Application Architecture Multi-tier architecture http e.g. RMI JDBC ODBC

Homework 7: Architecture Tomcat 6.0 Twitter app JSP, Java Web Server newcastle.db.cs.cmu.edu PostgreSQL Database Server newcastle.db.cs.cmu.edu hw7 database Client Browser User http JDBC

Registration example – register.jsp Tomcat 6.0 Twitter app JSP, Java Web Server newcastle.db.cs.cmu.edu PostgreSQL Database Server newcastle.db.cs.cm u.edu hw7 database Client Browser User /testuser41 5/register.jsp register.jsp html page with input FORM Submit FORM with login_id, password and JDBC exec. query java.sqlStatement. executeUpdate() JDBC insert succeeds Html page with successful info

Registration example – register.jsp

Registration example – register.jsp (continued)

JSP Basics JSP is a technology that helps software developers serve dynamically generated web pages Similar to PHP and ASP (Microsoft), but using Java: It simply “put Java inside HTML”.

JSP Basics Three primitives – expressions – directives – declarations

JSP Basics – expressions JSP is being turned into a Java file, compiled and loaded enclose Java expressions, which are evaluated at run time Scriptlets: blocks of Java code ( ) Hello! The time is now

JSP Basics – directives JSP "directives" starts with characters. "page directive": can import external java (can be user- defined) classes. “include directive”: can include other jsp/html files.

JSP Basics – declarations The JSP code turns into a class definition. All the scriptlets are placed in a single method of this class. Can add variable and method declarations to this class. These variables and methods can later be “called” from your scriptlets and expressions. sequences enclose your declarations <%! Date theDate = new Date(); Date getDate() { System.out.println( "In getDate() method" ); return theDate; } %> Hello! The time is now

JSP Basics - communication w/ server A "request" in server-side processing refers to the transaction between a browser and the server. request.getParameter(“login”); // Common use: get the query string values A "response" is used to affect the response being sent to the browser. response.addCookie(cookie); // See later slide for Cookies response.sendRedirect(anotherUrl); // Tell browser to jump to another URL

Connect JSP to database <% … Connection conn = null; Statement stmt = null; ResultSet r = null; Class.forName("org.postgresql.Driver"); conn = DriverManager.getConnection ("jdbc:postgresql://localhost:40032/hw7? user=www&password=binf415"); stmt = conn.createStatement(); r = stmt.executeQuery( your-SQL-query ); if (r.next()) { session.setAttribute("login", r.getString(1)); … %> register.jsp

JSP Basics – Session management On a typical web site, a visitor might visit several pages and perform several interactions. If you are programming the site, it is very helpful to be able to associate some data with each visitor. For example, after a user logs in, you might want to keep the login name and/or other information of the user to maintain his/her credential. Two ways to implement in JSP: session, and cookies (optional).

JSP Basics – sessions (method#1) A session is an object associated with a visitor. If you open different browsers, or use different IPs, you are essentially use multiple sessions. Data can be put in the session and retrieved from it, much like a Hashtable. session.setAttribute( "theName", name ); session.getAttribute( "theName" ) Default expiration time: 30 minutes. You don’t need to change it in the homework.

JSP Basics – cookies (method#2) Cookies are commonly used for session management. short pieces of data sent by web servers to the client browser saved to clients hard disk in the form of a small text file helps the web servers to identify web users, by this way server tracks the user. (Optional)

Cookie example String username=request.getParameter("username"); Cookie cookie = new Cookie ("username",username); cookie.setMaxAge(365 * 24 * 60 * 60); response.addCookie(cookie); Welcome:. <%

JSP Basics – Exception Handling try { …. } catch (Exception ex) { ex.printStackTrace(); out.println("Login failed!"); out.println(" Go back to login! "); } // out: Output stream for page context, i.e., the content to show in the HTML.

Better Software Design? Design Pattern Design Patterns: Elements of Reusable Object-Oriented Software, Gamma, Erich; Richard Helm, Ralph Johnson, and John Vlissides Thinking in Patterns ( 0.9.zip) 0.9.zip Design Pattern for Web App: MVC pattern (Model – View – Controller) Basic idea: break software functionalities and interfaces Tool: struts (Optional)

MVC (Optional)