Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are.

Slides:



Advertisements
Similar presentations
4 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: Servlets.
Advertisements

3 Copyright © 2005, Oracle. All rights reserved. Designing J2EE Applications.
8 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: JavaServer Pages.
Java Server Pages (JSP)
Apache Struts Technology
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 24: Servlets Outline 24.1 Introduction 24.2 Servlet Overview and Architecture Interface.
Java Servlet & JSP © copyright 2005 SNU OOPSLA Lab.
28/1/2001 Seminar in Databases in the Internet Environment Introduction to J ava S erver P ages technology by Naomi Chen.
JSP Java Server Pages Reference:
Introduction to Servlet & JSP
Comp2513 Java Servlet Basics Daniel L. Silver, Ph.D.
CSCI 6962: Server-side Design and Programming History and Background.
Java Enterprise Edition Java Web Development Structure of a web project Introduction to Web Applications The first project Introduction to Java Web Development.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 37 - JavaServer Pages (JSP): Bonus for Java Developers Outline 37.1 Introduction 37.2 JavaServer.
Java Server Pages B.Ramamurthy. Topics for Discussion 8/20/20152 Inheritance and Polymorphism Develop an example for inheritance and polymorphism JSP.
Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are.
Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are.
Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are.
Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are.
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
Chapter 17 - Deploying Java Applications on the Web1 Chapter 17 Deploying Java Applications on the Web.
Java support for WWW Babak Esfandiari (sources: Qusay Mahmoud, Roger Impey, textbook)
® IBM Software Group © 2007 IBM Corporation JSP Custom Tags
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.
Introduction to JavaServer Pages (JSP) Slides from Dr. Mark Llewellyn.
COMP 321 Week 7. Overview HTML and HTTP Basics Dynamic Web Content ServletsMVC Tomcat in Eclipse Demonstration Lab 7-1 Introduction.
J2EE Structure & Definitions Catie Welsh CSE 432
® IBM Software Group © 2007 IBM Corporation J2EE Web Component Introduction
Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some.
Lecturer: Prof. Piero Fraternali, Teaching Assistant: Alessandro Bozzon, Advanced Web Technologies: Struts–
Stanisław Osiński, 2002JSP – A technology for serving dynamic web content Java Server Pages™ A technology for serving dynamic web content Stanisław Osiński,
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.
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.
Java Servlets & Java Server Pages Lecture July 2013.
SE-2840 Dr. Mark L. Hornick 1 Java Server Pages. HTML/JSPs are intended to be used as the views in an MVC- based web application Model – represents an.
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
A seminar on j2ee by saritha. s. What is J2EE J2EE (Java 2 Platform, Enterprise Edition) is a Java platform designed for the mainframe-scale computing.
CS-4220 Dr. Mark L. Hornick 1 Java Server Pages. HTML/JSPs are intended to be used as the views in an MVC- based web application Model – represents an.
Introduction to Server-Side Web Development Introduction to Server-Side Web Development Session II: Introduction to Server-Side Web Development with Servlets.
Java Servlets and Java Server Pages Norman White Stern School of Business.
Copyright © 2002 ProsoftTraining. All rights reserved. Java Servlets.
Middleware 3/29/2001 Kang, Seungwoo Lee, Jinwon. Description of Topics 1. CGI, Servlets, JSPs 2. Sessions/Cookies 3. Database Connection(JDBC, Connection.
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
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.
CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Basic JSP Celsina Bignoli Problems with Servlets Servlets contain –request processing, –business logic –response generation all lumped.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
Preface IIntroduction Objectives I-2 Course Overview I-3 1Oracle Application Development Framework Objectives 1-2 J2EE Platform 1-3 Benefits of the J2EE.
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
Java Servlets and Java Server Pages
CSI 3125, Preliminaries, page 1 JSP (Java Server Pages)
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.
Chapter 6 Chapter 6 Server Side Programming (JSP) Part 1 1 (IS 203) WebProgramming (IS 203) Web Programming.
 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,
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.
17 Copyright © 2004, Oracle. All rights reserved. Integrating J2EE Components.
CS 562 Advanced Java and Internet Application Computer Warehouse Web Application By Team Alpha :-  Puja Mehta (102163)  Mona Nagpure (102147)
Speaker Name Speaker Title Speaker Title Oracle Corporation Olivier Le Diouris Principal Product Manager Oracle Corporation Building Servlet and JSP Applications.
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 Servlets By: Tejashri Udavant..
Java Servlets.
MSIS 655 Advanced Business Applications Programming
J2EE Lecture 1:Servlet and JSP
Java Chapter 7 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are trademarks of Accenture. Application Delivery Fundamentals 2.0: Java Module 25: Java EE Overview, Servlets, and JSP

Copyright © 2012 Accenture All Rights Reserved. Module Objectives (1 of 2) Describe Enterprise Applications. State both Java Server Page (JSP) Architectural Models. Describe a Servlet and its use. Describe the purpose of a Java Servlet container. Demonstrate an understanding of Servlet lifecycle methods. Develop a Java Presentation Tier using a Servlet. At the end of this module, you will be able to: 2

Copyright © 2012 Accenture All Rights Reserved. Module Objectives (2 of 2) Describe the Java Server Pages scripting elements used in the JSP definition. Describe the compilation of Java Server Pages to Java Servlets. Describe the Java Server Pages life cycle. Identify Java Server Pages components. Demonstrate the use of JSP in a web- based application. 3

Copyright © 2012 Accenture All Rights Reserved. Agenda Introduction to Enterprise Applications Purpose of Architectural Models Servlets Java Server Page (JSP) Summary 4

Copyright © 2012 Accenture All Rights Reserved. [Portrait image size: 10.03cm x 6.67cm, position: 17.5cm x 5.41cm] Introduction to Enterprise Applications (1 of 2) An Enterprise Application is a business application, as opposed to a domestic application used in the home. These business applications are: Complex Scalable Distributed Component-based Mission-critical They may be deployed on a variety of platforms across corporate networks, intranets, or the Internet. 5

Copyright © 2012 Accenture All Rights Reserved. [Portrait image size: 10.03cm x 6.67cm, position: 17.5cm x 5.41cm] Introduction to Enterprise Applications (2 of 2) Designing and developing such enterprise applications means satisfying hundreds or thousands of separate requirements and every development decision may affect many other requirements. They are data-centric, user-friendly, and must meet stringent requirements for security, administration, and maintenance. 6

Copyright © 2012 Accenture All Rights Reserved. Purpose of Architectural Models JSP Model 1 Architecture Web Browser DB JSP Model Request Response Application Server Enterprise Server 7

Copyright © 2012 Accenture All Rights Reserved. Purpose of Architectural Models JSP Model 2 Architecture Web Browser DB (Controller) Servlet (View) JSP (Model) Request Response Instantiate Select View Application ServerEnterprise Server 8

Copyright © 2012 Accenture All Rights Reserved. Servlets Introduction (1 of 2) A Servlet: Is used as a server-side Java module for processing web-based client requests. Runs in a Servlet container under the Application Server (Tomcat). Enables communication between the front-end, business, and integration layers. Belongs to only one application and can be concurrently accessed by multiple requests. 9

Copyright © 2012 Accenture All Rights Reserved. Servlets Introduction (2 of 2) Server Side Web Container Servlet Container loginServlet Service () profileServlet Service () Network Application Server /loginSe rvlet?user= /loginSe rvlet?user= /loginSer vlet?user=n Browser 1 Browser 2 Browser 3 Browser n Client Side 080/loginServl et?user=2 10

Copyright © 2012 Accenture All Rights Reserved. Servlets Java Servlet Container Servlet container implements the Java Servlet specification and resides in an application server. All Servlets must be deployed to a compliant Servlet container. Service Lifecycle Management Security Threading Exception Handling Servlet service() Servlet Container Web Container 11

Copyright © 2012 Accenture All Rights Reserved. Servlets Lifecycle Methods Instantiation Initialization Invokes init() Service Invokes service() Destroy Invokes destroy() Unavailable Request Response 12

Copyright © 2012 Accenture All Rights Reserved. Servlets Develop Java Presentation Tier using a Servlet Browser Thick Client JSP Servlets POJO EJB JDBC RDBMS Client UI Layer Business Layer Data Access Layer Data Layer 13

Copyright © 2012 Accenture All Rights Reserved. Java Server Page Introduction A Java Server Page: Enables development of a dynamic user interface Is an extension of a Servlet Is a combination of: –Snippets of Java code –Hyper Text Markup Language (HTML) –JavaScript –Cascading Style Sheets (CSS) 14

Copyright © 2012 Accenture All Rights Reserved. Basic JSP: See It Demonstration: Faculty will demonstrate how to create a basic Java Server Page. Time Allocated: 10 minutes Environment or File: BasicJSPDemo.jsp Steps: 1.Open the project Week2CodebaseM25_participant 2.Navigate to the WebContent folder. 3.Open the BasicJSPDemo.jsp file 4.Follow the TODOs to create the four basic components: a.declaration, expression, scriptlet, and comments 5.Save the file 6.Run the JSP a.Right click on the JSP file b.Choose Run as, run on server 15

Copyright © 2012 Accenture All Rights Reserved. Basic JSP: Try It Now You Try It: Create a basic Java Server Page to display the characters A to Z.. Time Allocated: 15 minutes Environment or File: BasicJSPTryit.jsp Steps: 1.Open the project Week2CodebaseM25_participant 2.Navigate to the WebContent folder. 3.Open the BasicJSPTryIt.jsp file 4.Follow the TODO to write code to print characters A to Z. 5.Save the file 6.Run the JSP a.Right click on the JSP file b.Choose Run as, run on server 16

Copyright © 2012 Accenture All Rights Reserved. Basic JSP: Solution Your faculty will now provide you with the Solution to check and update your file. page language="java" contentType="text/html; charset=ISO " pageEncoding="ISO "%> Insert title here 17

Copyright © 2012 Accenture All Rights Reserved. Database Java Server Page Introduction - Architecture Model Servlet (Controller) Model View (JSP) JDBC 1. HTTP Request 3 4 Web Container JSP Container Web Server Web Browser 2. Request Redirect 9. HTTP Response 8. Response 18

Copyright © 2012 Accenture All Rights Reserved. Java Server Page Structure and Scripting Elements: Overview 19

Copyright © 2012 Accenture All Rights Reserved. Java Server Page Structure and Scripting Elements: Types JSP element types are used to: Createand access objects Definemethods Managethe flow of control Givespecial instructions to the container Generateoutput 20

Copyright © 2012 Accenture All Rights Reserved. Advanced JSP: See It (1 of 2) Demonstration: Faculty will demonstrate how to write an advanced Java Server Page that will create a form to accept student data and an ‘Add Student’ submit button. Time Allocated: 20 minutes Environment or File: AdvanceJSPDemo.jsp Steps Part 1: 1.Open the project Week2CodebaseM25_participant 2.Navigate to the WebContent folder. 3.Open the AdvanceJSPDemo.jsp file 4.Follow the TODO to add action and method HTML attributes to the form element. The action should invoke the NextJSPDemo.jsp 21

Copyright © 2012 Accenture All Rights Reserved. Advanced JSP: See It (2 of 2) Demonstration: Faculty Demo Continued – Part Two Steps Part Two: 1.Open the NextJSPDemo.jsp file 2.Follow the TODOs to add the SQL code to connect to the Faculty database and retrieve the form data from AdvanceJSPDemo.jsp and insert into the Student table. 3.Print the number of rows added. 4.Run AdvanceJSPDemo.jsp on the server 22

Copyright © 2012 Accenture All Rights Reserved. Advanced JSP: Try It (1 of 2) Now You Try It: Create an advanced Java Server Page that will create a form to accept employee data and an ‘Add Employee’ submit button. Time Allocated: 30 minutes Environment or File: AdvanceJSPTryIt.jsp Steps Part One: 1.Open the project Week2CodebaseM25_participant 2.Navigate to the WebContent folder. 3.Open the AdvanceJSPTryIt.jsp file 4.Follow the TODO to set the form attributes: a.Action to NextJSPTryIt.jsp b.Method to Post c.onsubmit to return validateForm() javascript 23

Copyright © 2012 Accenture All Rights Reserved. Advanced JSP: Try It (2 of 2) Now You Try It: Continue the Try It Environment or File: Eclipse Steps Part Two: 1.Open the NextJSPTryIt.jsp file 2.Follow the TODOs to add the SQL code to connect to the Participant database and retrieve the form data from AdvanceJSPTryIt.jsp and insert into the Employee table. 3.Print the number of rows added. 4.Run AdvanceJSPTryIt.jsp on the server 24

Copyright © 2012 Accenture All Rights Reserved. Advanced JSP: Solution (1 of 6) Your faculty will now provide you with the Solution to check and update your files. The AdvanceJSPTryIt code should look something like this: page language="java" contentType="text/html; charset=ISO " pageEncoding="ISO "%> ADF 2.0 Java Employee Registration System 25

Copyright © 2012 Accenture All Rights Reserved. Advanced JSP: Solution (2 of 6) The AdvanceJSPTryIt code should look something like this: Employee Registration Form Enter Employee Id Enter Employee Name Enter Department Id 26

Copyright © 2012 Accenture All Rights Reserved. Advanced JSP: Solution (3 of 6) The AdvanceJSPTryIt code should look something like this: 27

Copyright © 2012 Accenture All Rights Reserved. Advanced JSP: Solution (4 of 6) The NextJSPTryIt code should look something like this: page import="java.sql.*" language="java" contentType="text/html; charset=ISO " pageEncoding="ISO "%> ADF 2.0 Java <% final String INSERTQUERY = "insert into Employee values (?,?,?)"; String url = "jdbc:mysql://localhost/participant"; String user = "root"; String pass = "abcd1234"; 28

Copyright © 2012 Accenture All Rights Reserved. Advanced JSP: Solution (5 of 6) The NextJSPTryIt code should look something like this: Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection(url,user,pass); PreparedStatement ps = con.prepareStatement(INSERTQUERY); String id = (String)request.getParameter("employeeId"); String name =(String)request.getParameter("employeeName"); String departmentId = (String)request.getParameter("departmentId"); ps.setString(1,id); ps.setString(2,name); ps.setString(3,departmentId); con.setAutoCommit(false); int rows = ps.executeUpdate(); con.commit(); 29

Copyright © 2012 Accenture All Rights Reserved. Advanced JSP: Solution (6 of 6) The NextJSPTryIt code should look something like this: if(rows == 1) { %> 30

Copyright © 2012 Accenture All Rights Reserved. Java Server Page: Structure and Scripting Elements: JSP Implicit Objects Objects are created automatically by the Web container: –Need not be declared –Are accessible in JSP Objects contain important information, such as: –Request information –Application information –Page information 31

Copyright © 2012 Accenture All Rights Reserved. Java Server Page Compiled to Java Servlet JSP is compiled into a Java Servlet. Typically, each JSP is first translated into the Java source code for a Servlet class. The created Servlet is then compiled. The resulting Servlet is invoked to handle all requests for that page. The page translation step is performed the first time a given JSP is requested. 32

Copyright © 2012 Accenture All Rights Reserved. Java Server Page Life Cycle JSP file jspinit() Servlet file Servlet class _jspService() jspDestroy() 33

Copyright © 2012 Accenture All Rights Reserved. Java Server Page JSP Components: Introduction The Java Server Pages Standard Tag Library (JSTL) and Custom tags extend the JSP specification by adding a tag library for common tasks. Some of the common tasks are: –XML data processing –Conditional execution –Loops –Internationalization 34

Copyright © 2012 Accenture All Rights Reserved. Java Server Page JSP Components: JSP Standard Tag Library (JSTL) JSTL: –Encapsulates useful dynamic functionality. –Provides more readability and maintainability. JSTL has five tag libraries: –core –XML –sql –fmt –function 35

Copyright © 2012 Accenture All Rights Reserved. 1String firstName = request.getParameter("fName"); Java Server Page JSTL Example 1 2//Adds a tag library. Done only once in a JSP page to access all //its tags 3 4//Core tag library with an alias c. Creates a variable named //firstName and accesses the HTML page’s data using //${param. } Existing method using JSP Revised method using JSTL The following examples obtain a parameter value from an HTML page. 36

Copyright © 2012 Accenture All Rights Reserved. Java Server Page JSP Components: Custom Tags Custom tags are: Extensions to the JSP language. Powerful mechanisms that allow the developer to: –Create components that are unavailable in: Standard actions JSTL actions –Encapsulate functionality –Reuse those components in more than one application 37

Copyright © 2012 Accenture All Rights Reserved. Servlet: See It Demonstration: Faculty will demonstrate how to create a servlet to print ‘Hello World’ within a browser. Time Allocated: 10 minutes Environment or File: ServletDemo.java Steps: 1.Open the project Week2CodebaseM25_participant 2.Navigate to the Java Resources/src folder. 3.Open the package com.accenture.adf.newcodington.module25.sample 4.Open the ServletDemo.java file 5.Follow the TODOs to override the doGet method and print ‘Hello World’ 6.Run the Index.html file in the WebContent folder on the server 38

Copyright © 2012 Accenture All Rights Reserved. Servlet: Try It Now You Try It: Create a servlet to print the numbers 1 to 10 within a browser. Time Allocated: 20 minutes Environment or File: ServletTryIt.java Steps: 1.Open the project Week2CodebaseM25_participant 2.Navigate to the Java Resources/src folder. 3.Open the package com.accenture.adf.newcodington.module25.sample 4.Open the ServletTryIt.java file 5.Follow the TODOs to override the doGet method and print numbers from Run the Index.html file in the WebContent folder on the server 39

Copyright © 2012 Accenture All Rights Reserved. Servlet: Solution (1 of 3) Your faculty will now provide you with the Solution to check and update your file. package com.accenture.adf.newcodington.module25.sample; import java.io.IOException; public class ServletTryIt extends HttpServlet { private static final long serialVersionUID = 1L; /** HttpServlet#HttpServlet() */ public ServletTryIt() { super(); } 40

Copyright © 2012 Accenture All Rights Reserved. Servlet: Solution (2 of 3) The code should look something like this: // Overriding doGet method to print numbers from 1 to 10 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //Obtaining PrintWriter object from HttpServletResponse object PrintWriter pw = response.getWriter(); //Printing numbers. You may optionally print those in a table. pw.print(" "); pw.print(" Numbers "); for (int i = 1; i <= 10; i++) { pw.print(" "); pw.print(i); pw.print(" "); } pw.println(" Home "); } 41

Copyright © 2012 Accenture All Rights Reserved. Servlet: Solution (3 of 3) The code should look something like this: protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Calling doGet method from this method doGet(request, response); } 42

Copyright © 2012 Accenture All Rights Reserved. Activity 1: JSP and Servlets Objective: Create a web application to insert records into a Zoo table using JSP and Servlets. Instructions: Navigate to the Module 25, Activity 1 page on the course web site. Follow the instructions provided on the web page to complete the activity. 43

Copyright © 2012 Accenture All Rights Reserved. Questions and Comments 44

Copyright © 2012 Accenture All Rights Reserved. Module Summary (1 of 3) A Servlet enables communication between the front-end, business, and integration layers and must be deployed to a compliant Servlet container. That MVC2 supports reusability of application components. The Presentation Tier encapsulates the presentation logic and interfaces with a Client Tier. The key points from this module are: 45

Copyright © 2012 Accenture All Rights Reserved. Module Summary (2 of 3) A Java Server Page is a combination of: –Snippets of Java code –Hyper Text MarkUp Language (HTML) –Javascript –Cascading Style Sheets (CSS) A Web Server transfers the client’s request to be processed by Application Server. An Application Server processes the client’s request through the Model-View- Controller (MVC) pattern. 46

Copyright © 2012 Accenture All Rights Reserved. Module Summary (3 of 3) The JSP structure provides mechanisms to create and access implicit objects within scripting elements. Application objects can be accessed within a JSP page using Java and Enterprise Beans components. JSTL has five tag libraries: –core –XML –sql –fmt –function 47