15-415/615 Spring 2013 Homework 7 Building A Web Application

Slides:



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

Database System Concepts and Architecture
Apache Struts Technology
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
Bin Fu 03/27/ Spring 2012 Homework 7 Building A Web Application School of Computer Science.
Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Database Design Methodology handout.
Website Development Registering Users – Introducing Cookies.
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 Java Server Pages Can web pages be created specially for each user? What part does Java play?
PHP Scripts HTML Forms Two-tier Software Architecture PHP Tools.
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.
1 Guide to JSP common functions 1.Including the libraries as per a Java class, e.g. not having to refer to java.util.Date 2.Accessing & using external.
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.
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.
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.
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.
Server-Side Scripting with Java Server Page, JSP ISYS 350.
Elements of ASP Documents Adapted from MCDN Web Workshop ( and Webmonkey’s Introduction to Active.
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.
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.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 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.
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
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.
WEB SERVER SOFTWARE FEATURE SETS
MIT AITI 2004 JSP – Lecture 4 Sessions and Cookies.
Chapter 6 Chapter 6 Server Side Programming (JSP) Part 1 1 (IS 203) WebProgramming (IS 203) Web Programming.
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.
Java Server Pages Can web pages be created specially for each user?
CHAPTER 5 SERVER SIDE SCRIPTING
JSP Based on
WWW and HTTP King Fahd University of Petroleum & Minerals
Web Development Web Servers.
JSP (Java Server Page) JSP is server side technology which is used to create dynamic web pages just like Servlet technology. This is mainly used for implementing.
Java Server Pages.
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
PHP / MySQL Introduction
HW7: Database Application
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Database System Concepts and Architecture.
The Request & Response object
Lecture #19 (not in book) Database Design Methodology handout
Introduction of Week 11 Return assignment 9-1 Collect assignment 10-1
IntroductionToPHP Static vs. Dynamic websites
School of Computer Science
Tutorial 10: Programming with javascript
Web Application Development Using PHP
Presentation transcript:

15-415/615 Spring 2013 Homework 7 Building A Web Application School of Computer Science 15-415/615 Spring 2013 Homework 7 Building A Web Application 03/27/2012 1

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

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

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

Homework 7 Tasks to implement A recommendation web application for movies, like NetFlix. Users can register, like a movie, get recommendations, etc. Tasks to implement Registration (a simple example is already provided) Login/Logout Profile Page “Like” a movie Ask for a movie recommendation Reporting (website statistics) 5

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

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

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

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

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 external internal 10

Document forms (Homework I) D1: registration form login name password email D3: profile form login name? … List-of: Movies liked Dx: user record login name password email 11

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

E-R diagram (Homework I) passw ? email login ? ? like users movies ... Specify cardinalities Think about weak/strong entities 13

Relational schema (Homework I) users( login, passw, email … ) movies(… ) ? …. SQL DDL statements (Homework I) create table users (login char(20), passwd char (20) NOT NULL (?), … ); create table ? (… ); … 14

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

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

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

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 18

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

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

Registration example – register.jsp 1 http://newcastle.db.cs.cmu.edu:8080/testuser415/register.jsp Web Server newcastle.db.cs.cmu.edu Client Browser PostgreSQL Database Server newcastle.db.cs.cmu.ed u Tomcat 6.0 4 JDBC exec. query java.sqlStatement.executeUpdate() 2 html page with input FORM hw7 database User Twitter app JSP, Java 3 Submit FORM with login_id, password and email register.jsp JDBC insert succeeds 5 6 21 Html page with successful info

Registration example – register.jsp 22

Registration example – register.jsp (continued) 23

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”. 24

JSP Basics Three primitives – expressions – directives – declarations 25

JSP Basics – expressions JSP is being turned into a Java file, compiled and loaded <%= and %> enclose Java expressions, which are evaluated at run time Scriptlets: blocks of Java code (<% and %>) <HTML> <BODY> Hello!  The time is now <%= new java.util.Date() %> </BODY> </HTML> 26

JSP Basics – directives JSP "directives" starts with <%@ characters. "page directive": can import external java (can be user-defined) classes. <%@ page import="java.util.*, MyPackage.MyClass" %> “include directive”: can include other jsp/html files. <%@ include file="hello.jsp" %> 27

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. <%! and %> sequences enclose your declarations <%@ page import="java.util.*" %> <HTML> <BODY> <%!     Date theDate = new Date();     Date getDate()     {         System.out.println( "In getDate() method" );         return theDate;     } %> Hello!  The time is now <%= getDate() %> </BODY> </HTML> 28

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 29

Connect JSP to database register.jsp <% … 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=415pass"); stmt = conn.createStatement(); r = stmt.executeQuery(your-SQL-query); if (r.next()) { session.setAttribute("login", r.getString(1)); %> 30

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). 31

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.  32

JSP Basics – cookies (method#2) (Optional) 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. 33

Cookie example String username=request.getParameter("username"); Cookie cookie = new Cookie ("username",username); cookie.setMaxAge(365 * 24 * 60 * 60); response.addCookie(cookie); <% String cookieName = "username"; Cookie cookies [] = request.getCookies (); Cookie myCookie = null; if (cookies != null){ for (int i = 0; i < cookies.length; i++) { if (cookies [i].getName().equals (cookieName)){ myCookie = cookies[i]; break; } } } %>  <p>Welcome: <%=myCookie.getValue()%>. <% 34

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

Better Software Design? (Optional) 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 (http://www.mindviewinc.com/downloads/TIPatterns -0.9.zip) Design Pattern for Web App: MVC pattern (Model – View – Controller) Basic idea: break software functionalities and interfaces Tool: struts 36