Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.

Slides:



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

Servlets, JSP and JavaBeans Joshua Scotton.  Getting Started  Servlets  JSP  JavaBeans  MVC  Conclusion.
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.
J.Sant Servlets Joseph Sant Sheridan Institute of Technology.
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
CSE 190: Internet E-Commerce Lecture 7. HTML Templates Designed to separate server side logic from HTML presentation Key features –Escapes from HTML into.
An introduction to Java Servlet Programming
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
Comp2513 Java Servlet Basics Daniel L. Silver, Ph.D.
Java Server and Servlet CS616 Team 9 Kim Doyle, Susan Kroha, Arunima Palchowdhury, Wei Xu.
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.
Server Side Programming Web Information Systems 2012.
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.
Servlets. Our Project 3-tier application Develop our own multi-threaded server Socket level communication.
CSCI 6962: Server-side Design and Programming History and Background.
Java Servlets and JSP.
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.
Introduction Servlets and JSP Celsina Bignoli
1 Servlet How can a HTML page, displayed using a browser, cause a program on a server to be executed?
Servlets. - Java technology for Common Gateway Interface (CGI) programming. - It is a Java class that dynamically extends the function of a web server.
AN OVERVIEW OF SERVLET TECHNOLOGY SERVER SETUP AND CONFIGURATION WEB APPLICATION STRUCTURE BASIC SERVLET EXAMPLE Java Servlets - Compiled By Nitin Pai.
Java support for WWW Babak Esfandiari (sources: Qusay Mahmoud, Roger Impey, textbook)
CSC 2720 Building Web Applications
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
SKT-SSU IT Training Center Servlet and JSP. Chapter Three: Servlet Basics.
111 Java Servlets Dynamic Web Pages (Program Files) Servlets versus Java Server Pages Implementing Servlets Example: F15 Warranty Registration Tomcat Configuration.
DataBases and SQL INFSY 547 Spring Course Wrap Up April 12: Complete Work on Servlets Review of Team Projects Close of Portfolio Work April 19:
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,
Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some.
Servlet Lifecycle Lec 28. Servlet Life Cycle  Initialize  Service  Destroy Time.
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.
Java Servlets Outline 24.1 Introduction 24.2 Servlet Overview and Architecture Interface Servlet and the Servlet Life Cycle HttpServlet Class.
Java Servlets & Java Server Pages Lecture July 2013.
Java Servlets Lec 27. Creating a Simple Web Application in Tomcat.
1 CS122B: Projects in Databases and Web Applications Spring 2015 Notes 03: Web-App Architectures Professor Chen Li Department of Computer Science CS122B.
20-Nov-15introServlets.ppt Intro to servlets. 20-Nov-15introServlets.ppt typical web page – source Hello Hello.
S ERVLETS Hits Counter 21-Nov-15. S ERVLETS - H ITS C OUNTER Many times you would be interested in knowing total number of hits on a particular page of.
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.
Java Servlet API CGI / HTTP Concepts Java Servlet API.
@2008 Huynh Ngoc Tin Chapter #2 JAVA SERVLET PRGRAMMING.
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.
1 Java Servlets l Servlets : programs that run within the context of a server, analogous to applets that run within the context of a browser. l Used to.
 2002 Prentice Hall. All rights reserved. 9.8 Multi-Tier Applications: Using JDBC from a Servlet Three-tier distributed applications –User interface –Business.
Middleware 3/29/2001 Kang, Seungwoo Lee, Jinwon. Description of Topics 1. CGI, Servlets, JSPs 2. Sessions/Cookies 3. Database Connection(JDBC, Connection.
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.
CS320 Web and Internet Programming Introduction to Java Servlets Chengyu Sun California State University, Los Angeles.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
How CGI and Java Servlets are Run By David Stein 14 November 2006.
S ERVLETS Form Data 19-Mar-16. F ORM P ROCESSING You must have come across many situations when you need to pass some information from your browser to.
1 Web Programming with Servlets & JSPs WEB APPLICATIONS – AN OVERVIEW.
CS122B: Projects in Databases and Web Applications Spring 2017
Introduction to Servlets
CS122B: Projects in Databases and Web Applications Winter 2017
Servlets.
Servlet Fudamentals.
Java Servlets By: Tejashri Udavant..
Chapter 26 Servlets.
CS122B: Projects in Databases and Web Applications Winter 2018
CS122B: Projects in Databases and Web Applications Spring 2018
COP 4610L: Applications in the Enterprise Spring 2005
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
CS122B: Projects in Databases and Web Applications Winter 2019
Java Chapter 7 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

Requesting a Web Page over the Internet: (two-tiered architecture) Works best for smaller companies Client requests information User interface usually here Server receive information and processes it Data Base services are usually on a server

Client/Server Software Multi-tier architecture Improves performance for larger numbers of users Middle tier can perform services e.g.  queuing,  application execution,  database The middle layer may also add scheduling and prioritization handling.

Many Software Options  php  jsp  servlets  CGI  Server side javascript  Microsoft active server pages  VBScript  Perl AND MORE

Common Gateway Interface (CGI)  Protocol used between a browser and server software  Has been a standard for interfacing external applications with information servers, such as HTTP servers.  See Chapter 10 of your text Server Request for CGI Internet

Java Servlets  Advantages  Time  Portable  Powerful  Developed in an object-oriented language  Secure (security provided by WEB server and also coding)  Platform independent  Work well with databases

Java Server Pages Java Server Pages (JSP) Extension of servlets Facilitates use of “scriptlets” of Java code directly on the page Compiled into servlets Chapter 11,

Hosted in a container. Part of JAVA Servlets

TomCat A container for hosting Java Applications:  Java servlets  jsp applications A nested environment of component parts We will set up and use along with Oracle database environment  accessed via the servlet  accessed via lab TomCat container may be downloaded (see TomCat Instructions attached to Syllabus)

Java Servlets Architecture  Two packages are important to our use of servlets  GenericServlet (import javax.servlet)  HttpServlet (import javax.servlet.http )  Most servlets extend one or the other  WEB servlets usually extend HttpServlet.

 Several methods in these packages below are called automatically import javax.servlet.*; import javax.servlet.http.*;

Java Servlets Life Cycle 1) init () method is called as “life” begins 2) services () services all requests and is first method called a) Normally this method is not implemented directly by programmer b) In our applications we will be using service in HttpServlet class 3) destroy () is called at the end servlet’s life

HttpServlet  Defines processing for servlets that extend functionality of a WEB server.  We will extend HttpServlet class

HttpServlet  The methods in HttpServlet to accomplish tasks are called by service ():  doGet  doPost (Others are on Page 432 of text, Table 11.1)

 Arguments of doPost and doGet  Make it easy to access data HttpServletRequest and HttpServletResponse

HttpServlet  Requests: contain data passed between the client and the server  Common Request Types:  doGet : to supply data as part of the request  Parameters are passed to a servlet as name/value pairs  Caches the data obtained for fast processing Next Page for the “doPost”

HttpServlet  doPost: to post data to a WEB server  Subtle difference – post will not cache the information  Often used to obtain form information

Lets Try It! Create a new Java project in the Eclipse Development Environment Project Name: WelcomeServletSP07 Next

Adding servlet library to project! Libraries Add External Jar In TomCat – Common/lib Servlet-api.jar

Create a WelcomeServletSP07 class in the IDE import javax.servlet.*; import javax.servlet.http.*; //handles get and post requests //implements servlet.Servlet import java.io.*;

Alternately import javax.servlet.*; import javax.servlet.http.*; import java.io.IOException; import java.io.PrintWriter;

Add global variables public class WelcomeServletSP07 extends HttpServlet { static final private String CONTENT_TYPE = "text/html"; String firstName; String lastName; String Name;

Create doGet Method/initialize variables protected void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { firstName = request.getParameter( "firstName" ); lastName = request.getParameter ("lastName"); Name = request.getParameter(" Name"); response.setContentType( CONTENT_TYPE); PrintWriter out = response.getWriter();

Complete doGet Method out.println (" " + " " + " "); out.println(" "); out.println( " Processing get requests with data " ); out.println( " " ); out.println( " Hello " + firstName + " " + lastName + " " ); out.println( " Address: " + Name + " " ); out.println(" The servlet has received a GET. " + "This is the reply. "); out.println( " " ); out.close(); }

doGet Procedure overridden public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException //if doGet cannot handle a response or encounters //any error, it will throw an exception!

{ response.setContentType(CONTENT_TYPE); //Note: String CONTENT_TYPE = "text/html“ //indicates that the response goes to a browser PrintWriter out = response.getWriter(); //getWriter () obtains a reference to PrintWriter //to send output to the client. }

{. out.println (" " + " " + " "); out.println(" "); out.println( " Processing get requests with data " ); out.println( " " ); } //Creates an html document which has //the response to the get

Processing get requests with data <form action="../servlet/WelcomeServletSP07" method="get"> Type information requested and press the Submit button First Name: Last Name: Address:<input type ="text" name=" Name" size="20"/>

1.Add code to obtain: a)streetName b)cityName c)zipName from the form Add code to print all information on the screen

Lab Completion! 1.Expand the form on the html page to include the needed inputs.

TomCat Configuration

1.WEB-INF (in servlet-examples) a.classes – places.class file in this location b.May want to keep.java files here also 2.servlets-examples directory a.Place.html files in this directory

examples/ WelcomeServletSP07.html 1.Update the web.xml file according to instructions for TomCat 2.Your Servlet can now be run in a browser: