Servlets api overview

ramyamarichamy 897 views 15 slides Sep 05, 2018
Slide 1
Slide 1 of 15
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15

About This Presentation

about servlets api overview


Slide Content

SERVLETS API OVERVIEW PRESENTED BY M.RAMYA M.sc (CS & IT) NADAR SARASWATHI COLLEGE OF ARTS & SCIENCE, THENI.

SERVLETS Servlets used to create web application Servlets are middle layer of between a request from browser or HTTP client and database application. Servlets are robust and scalable Servlets are platform independent Servlets resides at server side and generates dynamic web page

Servlets are used to collect input through the web forms or to show records from database via web reports. Servlets performance is significantly better than CGI. Servlets execute within the address space of a Web server. So it is not necessary to create a separate process to handle each client request. Servlets are secure.

SERVLETS – DIAGRAMMATIC REPRESENTATION Web browser HTTP Server Servlet Program Database

SERVLETS EXECUTION STEPS : Browser or any HTTP client sent data to the HTTP Server in the form of Web Page. The request sent by the Browser or client is read by Servlets. Request or data sent includes Servlet then processes the data and generate the results. Servlet then Sends data to the clients (browsers) in verity of formats which includes web page, Images, pdf or excel No. Request Sent by Browser includes 1 HTML Form 2 cookies 3 media types 4 compression schemes etc

DIFFERENT TERMS USED IN SERVLET TECHNOLOGY : Term Description HTTP Protocol allows web servers and browsers to exchange data over the web Get and Post method Methods for a request-response data between a client and server Container Run time environment for Java EE applications Application Server A server that exposes business logic to client applications through various protocols including HTTP. Web Server A server that handles HTTP protocol. Content Type HTTP header which provides the description about what are you sending to the browser. Deployment Activity by which make a web application available for use

SERVLET API Before creating the first servlets, you need to understand the Servlet API and Tomcat Servlet container. The Servlet API provides interfaces and classes that are required to built servlets. These interfaces and classes are group into the following two packages : javax.servlet javax.servlet. Http

JAVAX.SERVLET PACKAGE The javax.Servlet package contains a number of interfaces and classes that establish the framework in which servlets operate. The classes and interface in this package are protocol independent. The Fig. shows classes and interfaces in this package.

The javax.servlet package contains many interfaces and classes. Some of the interfaces and classes  are listed in table. Interfaces Description Servlet Declares life cycle methods that all servlets must implement. ServletConfig Allows servlets to get initialization parameters ServletContext Allows servlets to communicate with its servlet container. ServletRequest Provides client request information to a servlet. ServletResponse Assist a servlet in sending a response to the client.

Classes Description GenericServlet Provides a basic implementation of the Servlet interface for protocol independent servlets ServletlnputStream Provides an input stream for reading binary data from a client request. ServletOutputStream Provides an output stream for sending binary data to the client. ServletException Defines a general exception, a servlet can throw when it encounters difficulty. UnavailableException Indicates that a servlet is not available to service client request.

WRITING SERVLETS Servlet is an extension to a server that enhances the server's functionality. The most common use for a servlet is to extend a web server by providing dynamic web content . Web servers display documents written in HyperText Markup Language (HTML) and respond to user requests using the HyperText Transfer Protocol (HTTP). HTTP is the protocol for moving hypertext files across the internet. HTML documents contain text that has been marked up for interpretation by an HTML browser such as Netscape.

SIMPLE SERVLETS HANDLING HTML Handling form data represented in HTML page is a very common task in web development. A typical scenario is the user fills in fields of a form and submits it. The server will process the request based on the submitted data, and send response back to the client.

To create a form in HTML we need to use the following tags:   <form>: to create a form to add fields in its body. < input>, <select>, <text area>…: to create form fields like text boxes, dropdown list, text area, check boxes, radio buttons,… and submit button.
Tags