CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, Responds oriented other.

Slides:



Advertisements
Similar presentations
CGI programming. Common Gateway Interface interface between web server and other programs (cgi scripts) information passed as environment variables passed.
Advertisements

 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
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.
An introduction to Java Servlet Programming
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 34 Servlets.
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.
1 CS6320 – Servlet Structure and Lifecycle L. Grewe.
Comp2513 Java Servlet Basics Daniel L. Silver, Ph.D.
Java Server and Servlet CS616 Team 9 Kim Doyle, Susan Kroha, Arunima Palchowdhury, Wei Xu.
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.
Session-02.
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.
SE-2840 Dr. Mark L. Hornick1 Java Servlet-based web apps Servlet Architecture.
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.
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.
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.
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 & Java Server Pages Lecture July 2013.
Java Servlets Lec 27. Creating a Simple Web Application in Tomcat.
20-Nov-15introServlets.ppt Intro to servlets. 20-Nov-15introServlets.ppt typical web page – source Hello Hello.
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.
Middleware 3/29/2001 Kang, Seungwoo Lee, Jinwon. Description of Topics 1. CGI, Servlets, JSPs 2. Sessions/Cookies 3. Database Connection(JDBC, Connection.
Servlets.
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.
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)
©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.
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,
How CGI and Java Servlets are Run By David Stein 14 November 2006.
1 Lecture 8 George Koutsogiannakis/Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
1 Web Programming with Servlets & JSPs WEB APPLICATIONS – AN OVERVIEW.
Distributed Web Systems Java Servlets Lecturer Department University.
Introduction to Servlets
Servlets.
Servlet Fudamentals.
Java Servlets By: Tejashri Udavant..
CSE 403: Servlet Technology
Servlet.
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.
J2EE Lecture 1:Servlet and JSP
Basic servlet structure
Java Chapter 7 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

CSI 3125, Preliminaries, page 1 SERVLET

CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, Responds oriented other server side prog GGI (perl) ASP (Microsoft) CGI -> every client request treat as separate process it takes time & resourses Asp-> every client request as separate thread It takes less time Servlet -> same as ASP Diff-> platform independent & can handle any type of request Does not depend on any protocol

CSI 3125, Preliminaries, page 3 Request & Responds model Client request some recourse to server Server servers the request server responds to the client request and return static page not dynamic Client request through the web -> (http request) http -> hyper text transfer protocol

CSI 3125, Preliminaries, page 4 Request & Responds model

CSI 3125, Preliminaries, page 5 Web server Client request for a page in the web server Server having set of static pages This static page (html) sends to client again http response Web server is a machine which can take client http request and response to client as static page

CSI 3125, Preliminaries, page 6 HTT Request Methods HTTP method Contains the parameters that send to the server It basically get or post Form parameters -> http request contains the form parameters such as username, password..

CSI 3125, Preliminaries, page 7 HTTP Response methods A Status code method -> from server to client that the request is successful or not Ie the requested page is found or not If not send error page Content type(text/img..) Content type method-> if the requested page is found in the server then specify what type of content will send to client It may be text/ img/jar file…. Content -> final data

CSI 3125, Preliminaries, page 8 SERVLET Web server cannot send dynamic page Helper application  servlet

CSI 3125, Preliminaries, page 9 SERVLET

CSI 3125, Preliminaries, page 10 Web container

CSI 3125, Preliminaries, page 11 Web container Client request to web server Webserver take help of servlet (java prog) Webserver communicate with the servlet through web container (servlet engine) Servlet engine responsible for invoking all methods on servlet Container knows which method to call for that corresponding request in the servlet

CSI 3125, Preliminaries, page 12 How container Handle the request

CSI 3125, Preliminaries, page 13 How container Handle the request Container responsibility to send the request to servlet, allow the servlet to create dynamic page and return back to the webserver Request send by the client is http Reponses to the client also http Communication between webserver and container also http

CSI 3125, Preliminaries, page 14 How container Handle the request Servlet can understand only object (java code) Container translate the http request to valid request object If the request is get then container invoke the doGet() other wise doPost() With in the doGet() can write the code Finally java object response to the container Container converts the object reponds to webserver

CSI 3125, Preliminaries, page 15 How container knows which

CSI 3125, Preliminaries, page 16 SERVLET Package javax.servlet.x And Javax.servlet.http.x Need a servlet public class extends HttpServlet( generic servlet class) Servlet life cyle Init() -> service()->destroy() (same of applet) Init() and destroy() execute only once Service() execute every client request

CSI 3125, Preliminaries, page 17 SERVLET Service() contain the logic for processing the client request and responds to it All these methods from GenericServlet class (not specific any protocol) Servlet does not have User Interface JVM create an intense of Servlet class Init() -> execute one time (connect database)Or initialization Destroy()-> execute when not using for some time automatically destroy

CSI 3125, Preliminaries, page 18 SERVLET When implement servlet implement with get and post method doget() -> takes parameters from HttpServletRequest & HttpServletResponse dopost() ->takes parameters from HttpServletRequest & HttpServletResponse

CSI 3125, Preliminaries, page 19 SERVLET Service() from GenericServlet -> takes parameter from ServletRequest & ServletResponse When client request the form service() invoked at the container first All these are implemented by the container

CSI 3125, Preliminaries, page 20 SERVLET Container create objects to all methods all the methods The request object holds the request details Like where get or post method is used for request, what type of Brower Response object contains all the details of data the sent back

CSI 3125, Preliminaries, page 21 SERVLET get methos  default faster limited data Information can see in URL post method  after url not with url as separate Cannot see, unlimited data

CSI 3125, Preliminaries, page 22 SERVLET the request will sent to servlet container The service() in GericServlet Is overrided in HttpServlet With request and responds getMethod()  returns the getrequest postMethod()  return the postrequest

CSI 3125, Preliminaries, page 23 SERVLET Prog Specify What type of data sent back to the client (content type) If a text text/plane img image/jpg Html text/html

CSI 3125, Preliminaries, page 24 SERVLET Tomcat Webapps

CSI 3125, Preliminaries, page 25 Prog import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloWorld extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println(" "); out.println(" Hello World! "); out.println(" "); out.println(" Hello World! "); out.println(" "); }

CSI 3125, Preliminaries, page 26 Prog 2 html file Please enter your name:

CSI 3125, Preliminaries, page 27 Prog 2 java 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"); ServletOutputStream out = response.getOutputStream(); String userName = request.getParameter("user_name"); out.println(" "); out.println("\t Hello Servlet "); out.println(" "); out.println("\t Hello, " + userName + " "); out.println(" "); }

CSI 3125, Preliminaries, page 28 Session Tracking HTTP is a stateless protocol, where information is not automatically saved between HTTP requests. There are many situations in which we need to shared data between the servlets which are successively invoked during a session. ie there is a need to maintain the conversational state. This is done by session tracking

CSI 3125, Preliminaries, page 29 Session Tracking The different methods to achieve session tracking are Hidden fields  URL rewriting  Cookies  Session tracking API

CSI 3125, Preliminaries, page 30 COOKIES Cookies are the mostly used technology for session tracking.

CSI 3125, Preliminaries, page 31 Session Tracking Java Servlets send cookies to clients by adding fields to their HTTP response headers. Similarly, clients return cookies to servers by adding fields to HTTP request headers. When a client application (e.g., a Web browser) receives a cookie from a web server, the client application stores the cookie locally. A single browser can store 300 cookies where size of each cookie is limited to 4KB

CSI 3125, Preliminaries, page 32 Session Tracking THE COOKIE CLASS A Java cookie is an object of the javax.servlet.http.Cookie class. Cookies are created with the Cookie constructor. Cookie(String name, String value) Here, the name and value of the cookie are Eg Cookie cookie = new Cookie("CName","CookieValue");

CSI 3125, Preliminaries, page 33 Session Tracking

CSI 3125, Preliminaries, page 34 Session Tracking

CSI 3125, Preliminaries, page 35 Session Tracking

CSI 3125, Preliminaries, page 36 Session Tracking

CSI 3125, Preliminaries, page 37 Session Tracking