Middleware 3/29/2001 Kang, Seungwoo Lee, Jinwon. Description of Topics 1. CGI, Servlets, JSPs 2. Sessions/Cookies 3. Database Connection(JDBC, Connection.

Slides:



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

Java Servlet & JSP © copyright 2005 SNU OOPSLA Lab.
Introduction to Servlets Based on: Hall, Brown, Core Servlets and JavaServer Pages.
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.
10-Jun-15 Servlets. 2 Servers A server is a computer that responds to requests from a client Typical requests: provide a web page, upload or download.
Servlets and a little bit of Web Services Russell Beale.
An introduction to Java Servlet Programming
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 34 Servlets.
JSP Java Server Pages Reference:
1 CS6320 – Servlet Structure and Lifecycle L. Grewe.
Introduction to Servlet & JSP
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.
Definition Servlet: Servlet is a java class which extends the functionality of web server by dynamically generating web pages. Web server: It is a server.
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.
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.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
Java Server Pages B.Ramamurthy. Topics for Discussion 8/20/20152 Inheritance and Polymorphism Develop an example for inheritance and polymorphism JSP.
1 Servlet How can a HTML page, displayed using a browser, cause a program on a server to be executed?
Java Servelets. What Is a Servlet? A servlet is a Java programming language class used to extend the capabilities of servers that host applications accessed.
1 Chapter 2 The Web Tier  Web Applications and Web ContainersWeb Applications and Web Containers  Dynamic Content CreationDynamic Content Creation 
Servlets. - Java technology for Common Gateway Interface (CGI) programming. - It is a Java class that dynamically extends the function of a web server.
Objectives Java Servlet Web Components
Java support for WWW Babak Esfandiari (sources: Qusay Mahmoud, Roger Impey, textbook)
CSC 2720 Building Web Applications
111 Java Servlets Dynamic Web Pages (Program Files) Servlets versus Java Server Pages Implementing Servlets Example: F15 Warranty Registration Tomcat Configuration.
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.
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. Servlets When we run small Java programs within a browser these are referred to as Applets... And when we run small Java programs within.
Java Servlets & Java Server Pages Lecture July 2013.
Java Servlets Lec 27. Creating a Simple Web Application in Tomcat.
Servlets Server-Side Software. Objective What is a servlet? Where do servlets fit in? What can servlets do? Why are servlets better than CGI? Servlet.
Chapter 2 Web app architecture. High-level web app architecture  When a client request coming in and needs servlet to serve dynamic web content, what.
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.
L.MARIA MICHAEL VISUWASAM UNIT-4
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.
Servlets.
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.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
Java Servlets Java Server 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.
Java Servlets and Java Server Pages
CSI 3125, Preliminaries, page 1 JSP (Java Server Pages)
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.
 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,
Chapter 4 Request and Response. Servlets are controlled by the container.
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.
Distributed Web Systems Java Servlets Lecturer Department University.
Introduction to Servlets
Servlets.
Servlet Fudamentals.
Java Servlets By: Tejashri Udavant..
Chapter 26 Servlets.
Servlet APIs Every servlet must implement javax.servlet.Servlet interface Most servlets implement the interface by extending one of these classes javax.servlet.GenericServlet.
Java Chapter 7 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Middleware 3/29/2001 Kang, Seungwoo Lee, Jinwon

Description of Topics 1. CGI, Servlets, JSPs 2. Sessions/Cookies 3. Database Connection(JDBC, Connection pooling)

The Static Web Browser HTTP Server HTML Files Operating System HTTP Request HTML

The Dynamic Web Browser HTTP Server.java files Operating System HTTP Request HTML Servlet Engine Data Files JVM

The Dynamic Web To evolve from the static to the dynamic web requires: Generating HTML with scripts/programs CGI, Servlet Tools & techniques to make it manageable JSP Accessing and Updating data JDBC

CGI

CGI is not a language. It's a simple protocol that can be used to communicate between Web server and CGI program. A CGI script can be written in any language (Virtually any Programming language: C, Perl, shell script)

#include void main() { /** Print the CGI response header, required for all HTML output. **/ printf( “ Content-type:text/html\n\n ” ); /** Print the HTML response page to STDOUT. **/ printf( “ Hello,CGI \n ” ); printf( “ Hello CGI ” ); } CGI

CGI Pros and Cons Pros Simplicity Cons Performance problem Security problem

Servlet

Servlet Basics What is Servlet? A program written in Java that runs on the server, as opposed to the browser (applets). Invoked with “servlet” keyword in URL E.g.

Servlets vs. CGI Servlets have several advantages over CGI A Servlet does not run in a separate process. A Servlet stays in memory between requests. A CGI program needs to be loaded and started for each CGI request. There is only a single instance which answers all requests concurrently. This saves memory A Servlet can be run in a Sandbox, which allows secure use of untrusted and potentially harmful Servlets.Sandbox

Servlet Container (engine) Take and convert clients’ requests to an “object” understood by a servlet Provide an “object” to be used for response Manage the servlet lifecycle Make a servlet instance Call the instance’s init() Call the instance’s service() upon request Call the instance’s destroy() before destroying the instance Mark the instance for garbage collection

Add-on Servlet Engines Plug into popular web servers Stand-alone Servlet Engines Supports Web Server function JSDK(Java Servlet Development Kit)2.1 Apache JServ 1.1/Tomcat 3.2.1

Servlet Flow HTTP request response (HTML page) Servlet engine MyServlet

Servlet Flow A client Web browser submits HTTP request specifying servlet, e.g., The HTTP server receives the request from the client. The server parses the request and forwards it to the servlet.

Servlet Flow An instance of the servlet is created (or activated) to process the request. The servlet processes any form input data & generates an HTML response. This response is relayed back through the HTTP server to the client browser, which displays the page.

Temporary Servlets loaded on demand offer a good way to conserve resources in the server for less-used functions.

Permanent Servlets Loaded when the server is started, and live until the server is shutdown Servlets are installed as permanent extensions to a server when their start-up costs are very high (such as establishing a connection with a DBMS), they offer permanent server-side functionality (such as an RMI service) they must respond as fast as possible to client requests.

Key Servlet Packages Java Servlet API Defines the interface between servlets and servers javax.servlet javax.servlet.http

javax.servlet.Servlet Interface init(ServletConfig) Initializes the servlet. service(ServletRequest, ServletResponse) Carries out a single request from the client. destroy() Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. allow servlet to clean up any resources (such as open files or database connections) before the servlet is unloaded

getServletConfig() Returns a ServletConfig object, which contains any initialization parameters and startup configuration for this servlet. getServletInfo() Returns a string containing information about the servlet

HTTP Support Classes javax.servlet.http.HttpServlet provides an implementation of the javax.servlet.Servlet interface javax.servlet.http.HttpServletjavax.servlet.Servlet The easiest way to write an HTTP servlet is to extend HttpServlet and add your own processing. HttpServlet The class HttpServlet provides a service() method that dispatches the HTTP messages to one of several methods:HttpServletservice() doGet(), doPost(), doHead(), doDelete(), doPut() … doGet()doPost()doHead()doDelete() corresponding directly with the HTTP protocol methods.

A servlet's doGet() method shoulddoGet() Read request data, such as input parameters 00&interest=0.05 ····· 00&interest=0.05 Set response headers (length, type, and encoding) Write the response data

HelloServlet Example import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloServlet extends HttpServlet { public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println(" "); out.println(" Hello 서블릿 "); out.println(" 첫번째 서블릿 입니다. "); out.println(" "); }

Servlet - features Platform-independent Performance Easily extended due to class/package/bean concepts in Java

JSP

Why do we need JSP technology if we already have servlets?

JSP Combine static HTML and dynamic Java in one programming concept Simplified, fast creation of web pages that display dynamically-generated content. Separation of web presentation from web content Microsoft’s similar concept Active Server Pages

JSP JSP code is compiled into Java servlet class, then executed Remains in memory Only when any change in source file, repeat the first step

JSP tags Comment : HTML comment : Hidden comment Declaration Expression

JSP tags Scriptlet Include Directive Page Directive

Simple JSP Code 첫번째 jsp 페이지 first jsp page <% for (int i=0; i < 5; i++) { out.println(" " + i); } %>

More informations rvlets/Fundamentals/servlets.html rvlets/Fundamentals/servlets.html Servlet packages J2EE Documents J2SE v1.2.2 API Specification