@2008 Huynh Ngoc Tin Chapter #2 JAVA SERVLET PRGRAMMING.

Slides:



Advertisements
Similar presentations
Servlets, JSP and JavaBeans Joshua Scotton.  Getting Started  Servlets  JSP  JavaBeans  MVC  Conclusion.
Advertisements

 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
Technology Overview JAVA Servlets CS-611 S. Witherspoon.
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.
MC365 Application Servers: Servlets. Today We Will Cover: What a servlet is The HTTPServlet and some of its more important methods How to configure the.
Servlets and a little bit of Web Services Russell Beale.
An introduction to Java Servlet Programming
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 34 Servlets.
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.
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.
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.
Objectives Java Servlet Web Components
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.
111 Java Servlets Dynamic Web Pages (Program Files) Servlets versus Java Server Pages Implementing Servlets Example: F15 Warranty Registration Tomcat Configuration.
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.
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 & Java Server Pages Lecture July 2013.
Java Servlets Lec 27. Creating a Simple Web Application in Tomcat.
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.
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.
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
Java Servlet API CGI / HTTP Concepts Java Servlet API.
Introduction to Server-Side Web Development Introduction to Server-Side Web Development Session II: Introduction to Server-Side Web Development with Servlets.
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.
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.
JS (Java Servlets). Internet evolution [1] The internet Internet started of as a static content dispersal and delivery mechanism, where files residing.
CS320 Web and Internet Programming Introduction to Java Servlets Chengyu Sun California State University, Los Angeles.
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.
Java Servlets Java Server Pages (JSP)
Advanced Java Session 6 New York University School of Continuing and Professional Studies.
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
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
Chapter 4 Request and Response. Servlets are controlled by the container.
1 Lecture 8 George Koutsogiannakis/Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
1 Web Programming with Servlets & JSPs WEB APPLICATIONS – AN OVERVIEW.
Introduction to Servlets
Servlets.
Building Web Apps with Servlets
Servlet Fudamentals.
Java Servlets By: Tejashri Udavant..
Course Outcomes of Advanced Java Programming AJP (17625, C603)
HTTP Servlet Overview Servlets are modules that extend request/response-oriented servers, such as Java-enabled web servers. For example, a servlet might.
Chapter 26 Servlets.
Objectives In this lesson you will learn about: Need for servlets
Java Servlets and JSP.
J2EE Lecture 1:Servlet and JSP
Basic servlet structure
Java Chapter 7 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

@2008 Huynh Ngoc Tin Chapter #2 JAVA SERVLET PRGRAMMING

@2008 Huynh Ngoc Tin Objective  Basic concepts Why? What is java servlet? Servlet container Servlet life circle Servlet API, servlet interface …  Build, deploy, run a java servlet

@2008 Huynh Ngoc Tin References  [1] Chapter 3. Prentice Hall Ptr Java(Tm) Ee 5 Tutorial, The (3Rd Edition) (The Java Series)  [2] Marty Hall. Core Servlet and Java Server Page. Sun Micro System. Prentice Hall PTR; 1 edition  [3]

@2008 Huynh Ngoc Tin Basic concepts  Why?  What is java servlet?  What is servlet container?  Servets on J2EE/JEE Platform  Servlet Interface  Servlet Life Circle  Servlet context  Request/Response

The need for dynamic content. Applets, one of the earliest attempts toward this goal (the client side) At the same time, (CGI) scripts were the main technology used to generate dynamic content Limitation: Lack of scalability, Java Servlet technology was created as a portable way to provide dynamic, user- oriented Huynh Ngoc Tin Why?

@2008 Huynh Ngoc Tin What is java Servlet?  One of technologies of J2EE/JEE Platform.  Java Servlet is Java component that runs on web container.  Java Servlets “talks” to Web client base on request/ response that is managed by Servlet Container.

@2008 Huynh Ngoc Tin What is servlet container (Web container)?  A Web container is essentially the component of a Web server that interacts with the servlet.  The Web container is responsible for managing the life cycle of servlets  Mapping a URL to a particular servlet and ensuring that the URL requester has the correct access rights.

@2008 Huynh Ngoc Tin What is servlet container (Web container)?

@2008 Huynh Ngoc Tin Java Servlet on JEE Platform

The javax.servlet and javax.servlet.http packages provide interfaces and classes for writing servlets. The Java Servlet API allows a software developer to add dynamic content to a Web server using the Java platform. The generated content is commonly HTML, but may be other data such as XML. The HttpServlet class provides methods, such as doGet and doPost, for handling HTTP-specific Huynh Ngoc Tin Servlet API

@2008 Huynh Ngoc Tin Servlet API history Packages: javax.servlet & javax.servlet.http

@2008 Huynh Ngoc Tin Servlet Interface

@2008 Huynh Ngoc Tin Servlet Interface  Contains methods which are implemented by your servlets  Define methods to:  Init a java servlet.  Handle requests from the client side.  Remove servlet from the server.  Your Servlets can implements Servlet Interface or extends from a other class that implemented Servlet Interface such as GenericServlet & HttpServlet.

@2008 Huynh Ngoc Tin Servlet Interface public abstract class GenericServlet extends Object implements Servlet, ServletConfig, SerializableObjectServlet ServletConfigSerializable public abstract class HttpServlet extends GenericServlet implements SerializableGenericServletSerializable GenericServlet định nghĩa 1 servlet độc lập protocol, để định nghĩa 1 servlet dùng trên Web ta có thể cho kế thừa lớp HttpServlet.

@2008 Huynh Ngoc Tin Servlet Interface  Handle request service method: servlet Interface define service method to handle requests from the client side. Servlet Container will call service method to handle the request from the client side.

@2008 Huynh Ngoc Tin Servlet Interface  HttpRequest methods HttpServlet have some more methods to handle HttpRequest: doGet for handling HTTP GET requests doPost for handling HTTP POST requests … The above methods can are called automatically by service method

@2008 Huynh Ngoc Tin Servlet life circle Servlet container have only one instance for each servlet. Instance is handle by init, service, destroy in Servlet Interface (JEE API). Servlet Container load and init servlets. Servlet Container have init servlets before the request come from the client. Servlet Container have to choose a servlet for the request and make decision what servlet will be removed from the server.

@2008 Huynh Ngoc Tin Request & Reponse

@2008 Huynh Ngoc Tin Request & Reponse  Request Package all information that comes from the client. Request from Client -> Server follows the HTTP protocol HttpServletRequest methods can summarize, read the request’s information.

@2008 Huynh Ngoc Tin Request & Response  Response Package all information that will response for the client. Information in response object are sent to client by HTTT protocol HttpServletReponse methods can summarize, package information into response object.

Request & Response  Hypertext Transfer Protocol reference to:   

@2008 Huynh Ngoc Tin Example – Login Servlet  Step by step  Define a class name LoginServlet extends from GenericServlet or HttpServlet class  Implement/override the following methods init() service() destroy()  Compile and deploy on webserver.  Call to run by URL from the client side

@2008 Huynh Ngoc Tin Example – Login Servlet import javax.servlet.http.*; import java.io.*; import java.sql.*; public class LoginServlet extends HttpServlet { public void service(HttpServletRequest request, HttpServletResponse response) throws IOException{ // …. } }

@2008 Huynh Ngoc Tin Example – Login Servlet // inside the service method … response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println(" "); String strUsername = request.getParameter("Username"); String strPassword = request.getParameter("Password"); …

@2008 Huynh Ngoc Tin Example – Login Servlet Deploy the servlet on Apache Tomcat Web Server Web Server Apache Tomcat (read the document of other web servers to know how to deploy a servlet) Step 1: Copy servlet file class into WEB-INF\classes of your web application. Step 2: Add information about your servlet into web.xml file to notify with the web server or application server. WEB-INF\web.xml

@2008 Huynh Ngoc Tin Example – Login Servlet web.xml file (configuration) LoginServlet LoginServlet /servlets/LoginServlet

@2008 Huynh Ngoc Tin Example – Login Servlet Call a servlet from client side Call a servlet when user clicks submit or login button from the LoginForm/client side … …

Directly Using the connection pool Connecting to Database

@2008 Huynh Ngoc Tin Deploy a web app on Tomcat webserver

@2008 Huynh Ngoc Tin Exercises  Study by yourself client side programming such as HTML, Java Script.  Build, deploy and run servlets which do the below functions using NetBean 6.1 (include JBoss, GlassFish Application Server) Registration (RegisterServlet) Login (LoginServlet) Change password, registered information (UpdateUserInformationServlet)  Read more about JBoss, GlassFish, Tomcat document to deploy a java servlet