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.

Slides:



Advertisements
Similar presentations
Chapter 6 Server-side Programming: Java Servlets
Advertisements

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 10 Servlets and Java Server Pages.
4 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: Servlets.
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
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 and a little bit of Web Services Russell Beale.
Configuring web servers and web applications 1. 2 Server configuration vs. application configuration A web server may run several web application Server.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 34 Servlets.
1 CS6320 – Servlet Structure and Lifecycle L. Grewe.
Comp2513 Java Servlet Basics Daniel L. Silver, Ph.D.
Tomcat Configuration A Very, Very, Very Brief Overview.
Servlet details Russell Beale. Servlet lifecycle The servlet container creates only one instance of each servlet Each use request handled with a separate.
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.
Session-02.
SE-2840 Dr. Mark L. Hornick1 Java Servlet-based web apps Servlet Architecture.
Java Servlets and JSP.
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.
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.
Java Servlets CS-422. Application Mapping Your servlet application will be mapped to a directory structure: –“myapp” maps to some directory C:/docs/apps/myapp.
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
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.
CMPUT 391 – Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems Web based Applications,
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.
JSP Filters 23-Oct-15. JSP - FILTERS A filter is an object that can transform a request or modify a response. Filters are not servlets; they don't actually.
Chapter 6 Server-side Programming: Java Servlets
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.
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.
@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
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.
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.
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 Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a.
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Chapter 4 Request and Response. Servlets are controlled by the container.
1 Lecture 8 George Koutsogiannakis/Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
Introduction to Servlets
Servlets.
Servlet Fudamentals.
Java Servlets By: Tejashri Udavant..
CSE 403: Servlet Technology
Course Outcomes of Advanced Java Programming AJP (17625, C603)
Servlet API and Lifecycle
Introduction to 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.
Objectives In this lesson you will learn about: Need for servlets
COP 4610L: Applications in the Enterprise Spring 2005
Java Servlets and JSP.
CS3220 Web and Internet Programming Introduction to Java Servlets
J2EE Lecture 1:Servlet and JSP
Basic servlet structure
Java Chapter 7 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

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 application server to use your servlets Some example servlets Using properties files Some common errors and how to debug servlets

What is a Servlet? Sun describes a servlet in this way: –“A servlet is a Java programming language class used to extend the capabilities of servers that host applications access via a request-response programming model. Although servlets can respond to any type of request, they are commonly used to extend the applications hosted by Web servers. For such applications, Java Servlet technology defines HTTP- specific servlet classes. “ The javax.servlet and javax.servlet.http packages provide interfaces and classes for writing servlets. All servlets must implement the Servlet interface, which defines life-cycle methods.

HttpServlet Class When implementing a generic service, you can use or extend the GenericServlet class provided with the Java Servlet API. The HttpServlet class, though, provides methods, such as doGet and doPost, for handling HTTP- specific services. HttpServlets are best used to generate responses to HTTP requests. –This is the basis for web-based applications.

The LifeCycle of a Servlet? The life cycle of a servlet is controlled by the container in which the servlet has been deployed. When a request is mapped to a servlet, the container performs the following steps. 1.If an instance of the servlet does not exist, the Web container a.Loads the servlet class. b.Creates an instance of the servlet class. c.Initializes the servlet instance by calling the init method. 2.Invokes a service method, passing a request and response object. If the container needs to remove the servlet, it finalizes the servlet by calling the servlet's destroy method.

Important HTTPServlet Methods init –After the Web container loads and instantiates the servlet class and before it delivers requests from clients, the Web container initializes the servlet. –You can customize this process to allow the servlet to read persistent configuration data, initialize resources, and perform any other one-time activities by overriding the init method of the Servlet interface. –A servlet that cannot complete its initialization process should throw UnavailableException.

Important HTTPServlet Methods doGet and doPost –Called when browser makes an HTTP get request –Most calls are gets doPost –Called when browser makes an HTTP post request Usually you can handle both types of calls similarly

Important HTTPServlet Methods Finalize –When a servlet container determines that a servlet should be removed from service (for example, when a container wants to reclaim memory resources, or when it is being shut down), it calls the destroy method of the Servlet interface. In this method, you release any resources the servlet is using and save any persistent state. –All of a servlet's service methods should be complete when a servlet is removed. The server tries to ensure this completion by calling the destroy method only after all service requests have returned or after a server-specific grace period, whichever comes first.

An Example of a Servlet To see the source code for a very simple servlet, go to: Notes/SimpleServlet.java Notes/SimpleServlet.java

Configuring Tomcat to Use New Servlets Set context path –The context path is the first path name that comes after the url of your server In the url is the server name and porthttp://localhost:8080 /test is the context path Set the context path for new applications in the C:\Program Files\Apache Group\Tomcat 4.1\conf\server.xml. –Search for “context path” to find out where to make this change –You can see a sample server.xml file here.here You must restart the app server when you update the server.xml config file.

Configuring Tomcat to Use New Servlets Set servlet mappings –Servlet mappings refers to the mapping of servlets to url patterns. –In web.xml Invoker –To use a servlet name you must have invoker in servlet mapping in web.xml –test with Mappings –If you want to use a url other than the servlet name, use the servlet mapping tags. See a sample web.xml configuration file here.here

Configuring Tomcat to Use New Servlets Autoloading of servlets: –When you update servlets or web.xml you do not need to restart Tomcat –This is a nice feature of Tomcat.

Debugging Servlets Some common errors: –HTTP Status 404: This means that the page/servlet is not found. Either the servlet class is not in the classes folder or you did not configure the app server correctly. –HTTP Status 500: This is the error code you get when a servlet abends (ends abnormally). To correct this, fix the servlet. –Use logging to debug servlet issues. If you do not define your own logger, app server messages go to the stdout.log and stderr.log files in the logs directory.