Vakgroep Informatietechnologie – Onderzoeksgroep (naam) Web Centric Design of Distributed Software.

Slides:



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

Java Server Pages (JSP)
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
COMP 321 Week 8. Overview MVC Example Servlet Lifecycle Servlet Mechanics MVC Lab 5-2 Solution Lab 8-1 Introduction.
Servlets. A form The HTML source Chapter 1 Please enter your name and password then press start Name: Password: In Netbeans you can graphically create.
Servlets and JDBC. Servlets A form The HTML source Chapter 1 Please enter your name and password then press start Name: Password:
Objectives Ch. D - 1 At the end of this chapter students will: Know the general architecture and purpose of servlets Understand how to create a basic servlet.
Servlets Stoney Jackson
An introduction to Java Servlet Programming
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
JSP Java Server Pages Reference:
Servlets. A form The HTML source Chapter 1 Please enter your name and password then press start Name: Password: In Netbeans you can graphically create.
2/16/2004 Dynamic Content February 16, /16/2004 Assignments Due – Message of the Day Part 1 Due – Reading and Warmup Work on Message of the Day.
Integrating Servlets and JavaServer Pages Vijayan Sugumaran School of Business Administration Oakland University Parts of this presentation provided by.
Java database Programming JDBC Trademarked name of a Java API that supports Java programs that access relational databases Stand for Java DataBase Connectivity.
Servlet details Russell Beale. Servlet lifecycle The servlet container creates only one instance of each servlet Each use request handled with a separate.
Servlets Compiled by Dr. Billy B. L. Lim. Servlets Servlets are Java programs which are invoked to service client requests on a Web server. Servlets extend.
CSCI 6962: Server-side Design and Programming History and Background.
Java Servlets. What Are Servlets? Basically, a java program that runs on the server Basically, a java program that runs on the server Creates dynamic.
Servlet and JSP Programming: An Introduction Spiros Papadimitriou
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
Web Proxy Server. Proxy Server Introduction Returns status and error messages. Handles http CGI requests. –For more information about CGI please refer.
CSCI 6962: Server-side Design and Programming JDBC Database Programming.
Servlets Pranav Maydeo. What is a Servlet ? Servlets are modules of Java code that run in a server application to answer client requests. Servlets are.
AJAX and Java ISYS 350. AJAX Asynchronous JavaScript and XML: – Related technologies: JavaScript, Document Object Model, XML, server-side script such.
Li Tak Sing COMPS311F. A web page that counts the number of times that you have visited the page. You can try the page at:
Examples of Using Servlets and JSP Representation and Management of Data on the Internet.
Java support for WWW Babak Esfandiari (sources: Qusay Mahmoud, Roger Impey, textbook)
CSC 2720 Building Web Applications
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.
Java Servlets and Java Server Pages Carol Wolf Computer Science.
Li Tak Sing COMPS311F. Static attributes in Servlets Since Servlets are also Java classes, you can also use static attributes to store values that can.
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.
CMPUT 391 – Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems Web based Applications,
Chapter 3 Servlet Basics. 1.Recall the Servlet Role 2.Basic Servlet Structure 3.A simple servlet that generates plain text 4.A servlet that generates.
Servlets Database Access. Agenda:  Setup Java Environment  Install Database  Install Database Drivers  Create Table and add records  Accessing a.
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.
Chapter 9 Session Tracking. Session Tracking Basics Accessing the session object associated with the current request: Call request.getSession to get an.
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
Domain Driven Web Development With WebJinn Sergei Kojarski College of Computer & Information Science Northeastern University joint work with David H. Lorenz.
CSC 2720 Building Web Applications Frameworks for Building Web Applications.
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
@2008 Huynh Ngoc Tin Chapter #2 JAVA SERVLET PRGRAMMING.
Servlets Part 3. Topics Session Tracking ServletToServletCommunication-Servlet Chaining ServerSideIncludes AppletToServlet.
Li Tak Sing COMPS311F. A web page that counts the number of times that you have visited the page. You can try the page at:
JSP Pages. What and Why of JSP? JSP = Java code imbedded in HTML or XML –Static portion of the page is HTML –Dynamic portion is Java Easy way to develop.
Hints for Assignment #8. Initial Screen Hints for the initial page You need a DOCTYPE with the proper namespaces defined You need to import the facebook.
 2002 Prentice Hall. All rights reserved. 9.8 Multi-Tier Applications: Using JDBC from a Servlet Three-tier distributed applications –User interface –Business.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, Responds oriented other.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
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.
Introduction to Servlets. Introduction Servlet is a language to develop the server side applications, and it is also server side component. It can develop.
©SoftMoore ConsultingSlide 1 Filters. Filters can be used in a web application to intercept, examine, and possibly transform requests or responses associated.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
Slides © Marty Hall, book © Sun Microsystems Press 1 Session Tracking Core Servlets & JSP book: More.
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 21 Java Servlets Wed. 11/22/00 based on material.
Session Tracking Parts of this presentation was provided by SSE.
Introduction To HTML Dr. Magdi AMER. HTML elements.
ClaRA web services V. Gyurjyan Clas12 Software Meeting
How CGI and Java Servlets are Run By David Stein 14 November 2006.
 Java Server Pages (JSP) By Offir Golan. What is JSP?  A technology that allows for the creation of dynamically generated web pages based on HTML, XML,
1 Servlets – Part 2 Representation and Management of Data on the Web.
A Presentation Presentation On JSP On JSP & Online Shopping Cart Online Shopping Cart.
CS 562 Advanced Java and Internet Application Computer Warehouse Web Application By Team Alpha :-  Puja Mehta (102163)  Mona Nagpure (102147)
Introduction to Servlets
Java Servlets By: Tejashri Udavant..
Database Driven Websites
Presentation transcript:

Vakgroep Informatietechnologie – Onderzoeksgroep (naam) Web Centric Design of Distributed Software

Objectives After this lab session you should be able to Write dynamic web applications Using the following technologies: Servlets, JSP and AJAX Server side plug-ins (Servlets) Separate thread per request Shares resources with other servlets Java Server Pages Plain HTML used for static information Java-scriptlets to code the dynamic parts Jsp-file is compiled in single Servlet ODS – Introduction to Web Centric technologies Vakgroep Informatietechnologie p. 2

Objectives Asynchronous Javascript and XML (AJAX) Javascript technology to retrieve data from the server in the background No page refreshes ODS – Introduction to CORBA & RMI Vakgroep Informatietechnologie p. 3

Online Address Book ODS – Introduction to Web Centric technologies Vakgroep Informatietechnologie p. 4

Outline 1.Database 2.Database Access 3.Authentication 4.Showing the contacts 5.Viewing/adding/deleting contacts ODS – Introduction to Web Centric technologies Vakgroep Informatietechnologie p. 5

1. Database ODS – Introduction to Web Centric technologies Vakgroep Informatietechnologie p. 6

1. Database ODS – Introduction to Web Centric technologies Vakgroep Informatietechnologie p. 7

Outline 1.Database 2.Database Access 3.Authentication 4.Showing the contacts 5.Viewing/adding/deleting contacts ODS – Introduction to Web Centric technologies Vakgroep Informatietechnologie p. 8

2. Database Access Class to access the database Loads the correct driver Contains the connection url ODS – Introduction to Web Centric technologies Vakgroep Informatietechnologie p. 9 // Driver for the Derby database String driver = "org.apache.derby.jdbc.ClientDriver"; // Connection settings String dbName = "contacts"; String user = "nbuser"; String password = "nbuser"; String connectionURL = "jdbc:derby://localhost:1527/" + dbName; public DatabaseAccess() { try { Class.forName(driver); } catch(java.lang.ClassNotFoundException e) { … }

2. Database Access Data retrieval ODS – Introduction to Web Centric technologies Vakgroep Informatietechnologie p. 10 public ResultSet executeQuery(String query) { ResultSet results; try { // connect to the database Connection conn = DriverManager.getConnection(connectionURL, user, password); s = conn.createStatement(); results = s.executeQuery(query); return results; } catch (Exception e) { e.printStackTrace(); return null; }

2. Database Access Data update ODS – Introduction to Web Centric technologies Vakgroep Informatietechnologie p. 11 public void executeUpdate(String query) { try { // connect to the database Connection conn = DriverManager.getConnection(connectionURL, user, password); s = conn.createStatement(); s.executeUpdate(query); } catch (Exception e) { e.printStackTrace(); }

Outline 1.Database 2.Database Access 3.Authentication 4.Showing the contacts 5.Viewing/adding/deleting contacts ODS – Introduction to Web Centric technologies Vakgroep Informatietechnologie p. 12

3. Authentication Login form in index.jsp ODS – Introduction to Web Centric technologies Vakgroep Informatietechnologie p. 13 /LoginServlet"> User name: Password: Using the syntax we can generate dynamic output in a JSP

3. Authentication Login Servlet ODS – Introduction to Web Centric technologies Vakgroep Informatietechnologie p. 14 protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Get the username and password from the request String user = request.getParameter("username"); String pass = request.getParameter("password"); //Create the database object DatabaseAccess dbAccess = new DatabaseAccess(); ResultSet users; … } With request.getParameter() the encoded parameters of the form can be retrieved

3. Authentication Login Servlet ODS – Introduction to Web Centric technologies Vakgroep Informatietechnologie p. 15 // Get all users from the database users = dbAccess.executeQuery("select * from USERS"); try { while (users.next()) { String username = users.getString("username"); String password = users.getString("password"); if (username.equals(user) && password.equals(pass)) { // A match is found, access is allowed allowed = true; break; } // Close the resultSet users.close(); } catch (Exception e) { e.printStackTrace(); }

3. Authentication Login Servlet ODS – Introduction to Web Centric technologies Vakgroep Informatietechnologie p. 16 if (allowed) { // Add the username and database object to the session object HttpSession session = request.getSession(true); session.setAttribute("dbAccess", dbAccess); session.setAttribute("username", user); // Forward to the ContactsServlet RequestDispatcher dispatcher = request.getRequestDispatcher("ContactsServlet"); dispatcher.forward(request, response); } - The HttpSession object is used to bind a client to a servlet over multiple requests (session tracking) - The RequestDispatcher object is used to forward requests to other resources or to include the contents of another servlet to the response of this servlet

3. Authentication Login Servlet ODS – Introduction to Web Centric technologies Vakgroep Informatietechnologie p. 17 else { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); out.println(" "); out.println(" LoginServlet "); out.println(" "); out.println("You failed to supply valid credentials."); out.println(" "); out.close(); }

Outline 1.Database 2.Database Access 3.Authentication 4.Showing the contacts 5.Viewing/adding/deleting contacts ODS – Introduction to Web Centric technologies Vakgroep Informatietechnologie p. 18

4. Showing the contacts We need to check if the user has logged in properly User could go directly to url of ContactsServlet Check is needed throughout whole application Implemented in separated servlet ( CheckCredentialsServlet ) Included in other servlets via RequestDispatcher object ContactsServlet: ODS – Introduction to Web Centric technologies Vakgroep Informatietechnologie p. 19 … // Check if the user is logged in RequestDispatcher dispatcher = request.getRequestDispatcher("CheckCredentialsServlet"); dispatcher.include(request, response); …

4. Showing the contacts CheckCredentialsServlet ODS – Introduction to Web Centric technologies Vakgroep Informatietechnologie p. 20 PrintWriter out = response.getWriter(); // Get the username from the session HttpSession session = request.getSession(); String username = (String) session.getAttribute("username"); if (username == null) { // The user is not logged in out.println(" "); out.println(" CheckCredentialsServlet "); out.println(" "); out.println("You are not logged in. Click here to login."); out.println(" "); // close the output out.close(); }

4. Showing the contacts ContactsServlet: ODS – Introduction to Web Centric technologies Vakgroep Informatietechnologie p. 21 … // Get the username and database object from the session HttpSession session = request.getSession(); String username = (String) session.getAttribute("username"); DatabaseAccess databaseAccess = (DatabaseAccess) session.getAttribute("dbAccess"); … // Get all the contacts of the user String query = "select \"CONTACTNAME\" from USERCONTACTS where \"USERNAME\" = '" + username + "'"; ResultSet results = databaseAccess.executeQuery(query); try { while (results.next()) { String contactname = results.getString("contactname"); out.println(" " + contactname + " View Remove "); } …

Outline 1.Database 2.Database Access 3.Authentication 4.Showing the contacts 5.Viewing/adding/deleting contacts ODS – Introduction to Web Centric technologies Vakgroep Informatietechnologie p. 22

5. Viewing/adding/deleting contacts 3 extra servlets All information they need is sent via the urls or via the request body Each servlet includes CheckCredentialsServlet AddContactServlet: ODS – Introduction to Web Centric technologies Vakgroep Informatietechnologie p. 23 … // Update the CONTACTS table String query = "insert into CONTACTS Values('" + contactname + "','" + telephone + "','" + address + "')"; databaseAccess.executeUpdate(query); // Update the USERCONTACTS table String query2 = "insert into USERCONTACTS Values('" + username + "','" + contactname + "')"; databaseAccess.executeUpdate(query2); // Go back to ContactsServlet response.sendRedirect("ContactsServlet");