Leman Akoglu 11/11/2009 15-415 Fall 2009 Recitation Homework 9 Building A Web Application Phase-II School of Computer Science.

Slides:



Advertisements
Similar presentations
Michelle Johnston, Firebird Services Ltd
Advertisements

Bin Fu 03/27/ Spring 2012 Homework 7 Building A Web Application School of Computer Science.
Server-Side Scripting with Java Server Page, JSP.
Java, Access, SQL, HTML. Three-tier architecture involves: Client - Browser Server - Tomcat Database - Access - Server-side language - JSP could just.
Fundamentals, Design, and Implementation, 9/e Chapter 14 JDBC, Java Server Pages, and MySQL.
Servlets and a little bit of Web Services Russell Beale.
JSP Java Server Pages Reference:
Apache Tomcat Server – installation & use Server-side language-- use Java Server Pages Contrast Client-side languages HTML Forms Servers & Server-side.
Apache Tomcat Server Typical html Request/Response cycle
Java Server Pages Russell Beale. What are Java Server Pages? Separates content from presentation Good to use when lots of HTML to be presented to user,
Three-Tier Architecture Oracle DB Server Apache Tomcat App Server Microsoft Internet Explorer HTML Tuples HTTP Requests JDBC Requests Java Server Pages.
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.
Chapter 4 Servlets Concept of Servlets (What, Why, and How) Servlet API Third-party tools to run servlets Examples of Using Servlets HTML tag with GET.
Java Server Programming Jeff Schmitt Towson University October 15, 1998.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Java Server Pages B.Ramamurthy. Topics for Discussion 8/20/20152 Inheritance and Polymorphism Develop an example for inheritance and polymorphism JSP.
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.
SJSU CS157B Dr. Lee1  2004 Jenny Mitchell Two Useful Tools You Can’t Live Without by Jenny Mitchell SJSU CS157B Section PHP and MySQL.
IT533 Lectures Session Management in ASP.NET. Session Tracking 2 Personalization Personalization makes it possible for e-businesses to communicate effectively.
JDBC. JDBC Drivers JDBC is an alternative to ODBC and ADO that provides database access to programs written in Java.
Views, Indexes and JDBC/JSP tutorial Professor: Dr. Shu-Ching Chen TA: Haiman Tian 1.
Chapter 17 - Deploying Java Applications on the Web1 Chapter 17 Deploying Java Applications on the Web.
JSP Java Server Pages Softsmith Infotech.
Server-Side Scripting with Java Server Page, JSP ISYS 350.
Chapter 5 Java Servlets. Objectives Explain the nature of a servlet and its operation Use the appropriate servlet methods in a web application Code the.
Active Server Pages ASP is Microsoft’s server-side script engine for dynamically-generated web pages. Most common language used is VBScript. If you use.
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.
COMP 321 Week 7. Overview HTML and HTTP Basics Dynamic Web Content ServletsMVC Tomcat in Eclipse Demonstration Lab 7-1 Introduction.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
MySQL, Java, and JDBC CSE 3330 Southern Methodist University.
Database Programming using JSP and MySQL Byung-Hyun Ha
JDBC Tutorial MIE456 - Information Systems Infrastructure II Vinod Muthusamy November 4, 2004.
Server-Side Scripting with Java Server Page, JSP ISYS 350.
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.
Domain Driven Web Development With WebJinn Sergei Kojarski College of Computer & Information Science Northeastern University joint work with David H. Lorenz.
Mark Dixon 1 09 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 32.1 Reviewing the Bookstore Application 32.2.
Index and JDBC/JSP tutorial Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
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.
Jsp (Java Server Page) Is a server side program.
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.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 31.1 Reviewing the Bookstore Application 31.2.
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.
Mark Dixon 1 11 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
CSI 3125, Preliminaries, page 1 JDBC. CSI 3125, Preliminaries, page 2 JDBC JDBC stands for Java Database Connectivity, which is a standard Java API (application.
Basics of JDBC.
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
MIT AITI 2004 JSP – Lecture 4 Sessions and Cookies.
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.
1 Download current version of Tomcat from: g/tomcat/ g/tomcat/ Install it in: C:\Program Files\Apache.
Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing.
Java Server Pages Yes it is Java. What you should know HTML Java.
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.
1. Writing a Java program to connect to SQL Server 2008 and Create a table Populate the table (insert data) Perform queries to retrieve information from.
JSP Based on
Scripted Page Web App Development (Java Server Pages)
HW#4 Making Simple BBS Using JDBC
15-415/615 Spring 2013 Homework 7 Building A Web Application
HW7: Database Application
School of Computer Science
Tutorial 10: Programming with javascript
Presentation transcript:

Leman Akoglu 11/11/ Fall 2009 Recitation Homework 9 Building A Web Application Phase-II School of Computer Science

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 2

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 3

Outline Recommended Schema for HW9 A Typical Web Application Architecture CMUBook architecture JSP mini demo  register.jsp JSP Basics How to connect to the database Session and cookie management  login.jsp Exception handling Demo 4

Recommended Schema for HW9 users(login, password, name, ) photos(URL, owner) tags(URL, tagger, taggee, timestamp) likes(user1, user2) 5

Outline Recommended Schema for HW9 A Typical Web Application Architecture CMUBook architecture JSP mini demo  register.jsp JSP Basics How to connect to the database Session and cookie management  login.jsp Exception handling Demo 6

Users Web app (JSP, ASP, PHP) Apache, Tomcat, Windows IIS Web Server Java Virtual Machine Web app backend component Backend Server Database Server Client Typical Web Application Architecture http JDBC ODBC 7

Homework 9: CMUBook architecture Tomcat 5.5 CMUBook JSP, Java Web Server newcastle.db.cs.cmu.edu PostgreSQL Database Server newcastle.db.cs.cmu.edu hw9 database Client Browser User http JDBC 8

Outline Recommended Schema for HW9 A Typical Web Application Architecture CMUBook architecture JSP mini demo  register.jsp JSP Basics How to connect to the database Session and cookie management  login.jsp Exception handling Demo 9

CMUBook architecture Registration example –register.jsp Tomcat 5.5 CMUBook JSP, Java Web Server newcastle.db.cs.cmu.edu PostgreSQL Database Server newcastle.db.cs.cm u.edu hw9 database Client Browser User /lakoglu415 /register.jsp register.jsp html page with input FORM Submit FORM with login, name, password and JDBC exec. query java.sqlStatement. executeUpdate() JDBC insert succeeds Html page with successful info

Outline Recommended Schema for HW9 A Typical Web Application Architecture CMUBook architecture JSP mini demo  register.jsp JSP Basics How to connect to the database Session and cookie management  login.jsp Exception handling Demo 11

JSP Basics Three primitives – expressions – directives – declarations 12

JSP Basics – expressions JSP simply puts Java inside HTML pages. 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 13

JSP Basics – directives JSP "directives" starts with characters. "page directive": “include directive”: 14

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 15 <%! 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.getRemoteHost(); request.getParameter(“login”); A "response" is used to affect the response being sent to the browser. response.addCookie(cookie); response.sendRedirect(anotherUrl); 16

Outline Recommended Schema for HW9 A Typical Web Application Architecture CMUBook architecture JSP mini demo  register.jsp JSP Basics How to connect to the database Session and cookie management  login.jsp Exception handling Demo 17

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

Outline Recommended Schema for HW9 A Typical Web Application Architecture CMUBook architecture JSP mini demo  register.jsp JSP Basics How to connect to the database Session and cookie management  login.jsp Exception handling Demo 19

JSP Basics – sessions – method#1 Http protocol is a stateless protocol, that means that it can't persist the data. A session is an object associated with a visitor. Data can be put in the session and retrieved from it, much like a Hashtable. session.setAttribute( "theName", name ); session.getAttribute( "theName" ) 20

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. 21 (Optional)

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

Outline Recommended Schema for HW9 A Typical Web Application Architecture CMUBook architecture JSP mini demo  register.jsp JSP Basics How to connect to the database Session and cookie management  login.jsp Exception handling Demo 23

Exception Handling 24 try { …. } catch (Exception ex) { ex.printStackTrace(); out.println("Login failed!"); out.println(" Go back to login! "); }

Outline Recommended Schema for HW9 A Typical Web Application Architecture CMUBook architecture JSP mini demo  register.jsp JSP Basics How to connect to the database Session and cookie management  login.jsp Exception handling Demo 25

Lets put things together… 26 register.jsp <% String fullname = request.getParameter("fullname"); String = request.getParameter(" "); String login = request.getParameter("login"); String passwd = request.getParameter("passwd"); String submit = request.getParameter("submit"); if (submit==null) { %> CMUBook Registration Login Name: Full Name: Password:

27 <% } else { %> <% Connection conn = null; Statement stmt = null; try { Class.forName("org.postgresql.Driver"); conn = DriverManager.getConnection("jdbc:postgresql://localhost:40123/hw9?user=www&password=lakoglu415"); stmt = conn.createStatement(); int r = stmt.executeUpdate("INSERT INTO users(login, fullname, passwd, ) VALUES ('" + login + "','" + fullname + "','" + passwd + "','" + + "')"); if (r==1) { out.println("Registration successful!"); out.println(" Log In "); } else { out.println("Registration failed!"); } } catch (Exception ex) { ex.printStackTrace(); } finally { //this is important. You should free up resources. Always. In a finally block. stmt.close(); conn.close(); } %> <% } %>

Lets put things together… 28 login.jsp <% String login = request.getParameter("login"); String passwd = request.getParameter("passwd"); String submit = request.getParameter("submit"); if (submit==null) { %> CMUBook Login Page Login ID: Password: <% } else { %>

29 <% Connection conn = null; Statement stmt = null; ResultSet r = null; try { Class.forName("org.postgresql.Driver"); conn = DriverManager.getConnection("jdbc:postgresql://localhost:40123/hw9?user=www&password=lakoglu415"); stmt = conn.createStatement(); r = stmt.executeQuery("SELECT * FROM users WHERE login='" + login + "' and passwd='" + passwd + "'"); if (r.next()) { session.setAttribute("login", r.getString(1)); response.sendRedirect("user.jsp"); } else { out.println("Login failed!!"); out.println(" Log In "); out.println(" Register "); } } catch (Exception ex) { out.println("Login failed!"); } finally { //this is important. You should free up resources. Always. In a finally block. stmt.close(); conn.close(); } %> <% } %>

Lets put things together… 30 user.jsp Welcome