Servlet API and It Life Cycle Methods

Anjali Singh
A free video tutorial from Anjali Singh
Oracle certified J2EE Web Application Developer
3.7 instructor rating • 7 courses • 45,534 students

Lecture description

In this chapter , We will be explaining all about Servlet API and its life cycle methods in detail. By the end of this chapter, one can make servlet application

Learn more from the full course

Complete course of Java based web application development

Demonstration and Implementation of Java based web application development

02:42:51 of on-demand video • Updated

  • Students can create web application based on Java like Servlet, JSP, EJB , Struts Framework, and many more
English [Auto] Hi. Welcome to the ranch. A place where we learn and earn technical skills in the most efficient way. Let's make coding fun. Submit API tutorial chapter to subnet API and its lifecycle method. So in this video we are going to learn in detail about subnet API and its lifecycle method and the complete process in detail so far in the chapter 1 we learn about subnet architecture where we have learned about that line and web server and the complete process how a led process that is to be requisite and get the response to the client. And according to this architecture we have seen the browsers gods from the w w w dot line name goes to the server and from some inside the server with the help of the issue could be request it goes inside the web component and inside the solar container where the subnet API exist and then process the complete business logic and if in case it required contact database it goes to the database with the help of gbc and process the input and get the output and provide the response back to the line with the help book as duty TB response. So this was a complete process. We have learned new data about Soviet architecture. Now according to this architecture you can understand the subnet API exists within the server web server within the web server inside the subnet Peña. So this is where the subnet API exists. Let's learn about some red API in detail. The summit API is divided into three layer the top level the top layer consist of interfaces and abstract base classes that are not specific to any particular communication protocol. You can see the gender some that is available to all other FTB or HDD ATP if it is simply being kind of because you can use it. The second level consist of abstract classes and some interfaces that extend the Generate functionality for specific protocols. And the last and the third layer consist of classes that implement the full capability of the new above. So this is how it is different from one another and it is how it is structured in the layered form. But if you see the most commonly used replay request so let our user interface is a matron in this structure. The subnet request interface the subnet interface and subnet response with respect to your requirement. You just need to have implement these interfaces and overwrite these methods and use and implement the subnet. Just in case if you want to have a student request you just need to implement extra tables so that request and implement an overnight these methods get here to get header names get into the get to. Similarly if you have a generic sublet you just need or light overwrite it and it shouldn't be so late for the general purpose where we have the service method new get method to post method DREs do options destroyed new head and so many like this. These are the most commonly used. Then we have subnet response interface which has to be subnet response interface where you can overwrite set head on a method set HK to get data. These kind of most commonly used methods only use when implementation of some glitch let's learn a few important facts about subnet API subnet API exist with the callback methods for initialization and request processing these methods by which the subject can get configuration and environment of information access to protocol specific resources. So what does this mean. It depends what type of propaganda you are using for this particular request and response. Sometimes they have something kind of request or FTB type of request so that is specific to this EPA as we have interface is an abstract classes so there are some callback methods that you can use to initialize and override it. And this kind of methods needs a complete configuration and information environmental information that you will understand when we come up in the demonstration. Next we have request response API. That means that these requests and response getting it from the line of browser basically have some information. So communication is really important in this case from web server to web client and vice versa because retrieving from data pass data from one company into another retrieve security information generate outgoing output. All these things are very important to be making accurate and efficient clean. This is why so it is important to request object when the client got a thread to create a request and this object has to be implemented in the method and call in a method so that we can implement this offline. That means Request object is nothing but the object extended from the class should be subject request and this request object you can use and call to your implement the methods and call those methods which is already available in this public API and use and make this process extended. For example you are requesting for Lockman server and you create I.T. in password. So from browser the client is requesting for logging and giving you information. This information has to be passed on to the server. So with when it is Request object is created from the client the sunlight will implement those methods and call those callback those methods and get the information from the requisite positive the suddenly. So this process has to happen with the help of request object. Now next step response object just like request object response object with process from server to the client. We have this extra to be select response interface where we extend that implement Dr class public class to that interface and override those methods and call and communicate to the client. Similarly there are some more for example session management. We have filters we have tag handling exception handling. Similarly we have request this badgering phase which is another very interesting part of sort. Maybe what we can do we can forward the control and passing the data that we can do it discuss it in the daily during the next few chapters but for now this is one of the important interface. I just want to communicate with you what it has when it comes to the forward include kind of a process like you are forwarding a control from one some leg to another subject or another SDM or any other form of threat. What you can do you just create the request is that we implement the request dispatch your interface and all right forward method or include method and boss the control off the server from from the client using forward method or include the control of passing the data simply from server to client and waste. So this is all about the southern API in details. Let us learn about some net lifecycle method as you can see we have seen in the subnet architecture that is above component. Inside there we have solid container and that's where this already exists. Now let me start client request. It stopped from the init method which is defined in the US led API where we create an instance of request and request can be is any vertical. Suppose we. Since it isn't a web application development profile so you can have that extra could be request after creating an instance of its GDP request. The thread posted to the service method which is actually the main method where we write down the Met complete logic. What do you want to do in the server. So GDP service method has few methods. Which is just like an all right my turn. All you have to just overwrite and come up with some kind of functionality bit inside you can validate any form of data where you're collecting updates application data model or UK passes data to another company. I need to implement that to get my time. Now what is the difference between new post and do get and do trace when it is a form of get data. You have to give the new get method of either to get method and if it is a post type from the method it will be do post type of method and in the end you have to destroy the instance of request to dislocate the memory and release the instance to head and make it efficient process. This has to you know like the thread handily. It's kind of a thread handling helping you to making an efficient process less learned in detail about server lifecycle how it process. So you see we have a web server so let's learn about some lifecycle. If you'll see here we start from the client. The client will create an issue to give me request and send some little container. This is a web component and inside the web component we have any kind of container like suddenly container web container on your Egypt containers. What kind of application you have to be container. That's where it goes and it has a complete competence module. The module you see and inside of a module they have a different kind of containers which is the place where the subnet or any kind of container exist or API is our exist so solid container with a cerebral API uses exist how we process third request. Now number one we have the issue to be request number to it with process in the thread you already so try to e initiate the request and issued repeated ghost object and it will create an instance by using in it. So service method process the business logic by thread to. Now next step the tray to be will implement your service method and once the service method is implemented the service method return the issue to predict response to this of container and provide the response to the client. And number five the threat C that were removed the instance of this request and response completely. So this will help to reallocate the memory location created by the instance. So this is all about the service so lifecycle methods in detail. Now let's see a small demonstration of force. So let application. So all we have to have few things the environment set up in your system before going to the execution. But I have already set it up and we have the next chapter for the software navigation is to Asian guide. So for now I'm just going to show you how the subnet executed and why it is important. So all you have to have first create the dynamic of a publication. I have created this web app. It has read first on it which is written in Java. So we have it and don't jump off my creating issue Yemen index issue GMO and seven of this scripting language will be startup execution and deployment descriptor which is very important a kind of a property of the solid it's or any kind of obligation just God got a. How the directory structure goes here. You have a desk you have a folder inside that you have to have a glasses folder inside the Web. And I use them. And inside that you will describe your big three compiled class. You will have your index card estimator and the docking symbol inside the web. I notice when you go to the directory structure and how it process so dest web app is the application folder. So suppose the client tried to reach the best web application so late and it's asked for any information from the summit or seven it is asking for it something like a logging and don't ask CMO has some pros stopping to read information for the suddenly. So that starts from there. Not a similar exist some information that will go to the index dropped HD M.O. and date indexed on MDMA. A group called the first sublet the suddenly the main suddenly and process the request. Now I'll show you in a code if you see we have fuzz subject dark Java summit. This is my application. So let application. And this is my source app. The package. And first I've lived on jungle. So that's where my subnet is written. I have been shown here extend the extra extruded be select which has the Duplass method TDB so it is a class so we extend that class inside this class. We have do post method which we get over right here. I f overwrite it and I'm trying to getting the response from the index dot GMO file and calling my flows of late parameter and that first barometer whatever the user enter the log in 90 will be presented here that you will have logged in census. That's all I'm doing it here. Next you'll see the indexed on GMO file which exist here in this dark extreme of file. I am just making a form where I'm calling the name i.e. an object of store SDM object often request to linked it to the Soviet company gate to the public. It's a bar. It's a type of a post because I made it in a duplicate method or where I did the duplicate method action. This will board with a sample it is a package and source of it my sublet name. This is this index it has to be passed next name. I'm just getting the value the first so let the name value the first of it and that's it. Next most important is your vet dot eczema. The deployment descriptor. It's one of the kind of the properties of the application or separate application where we have the display name is there nothing you can have it. Anything which will just display on the IP address or your address office over Cyrillic name you'll plus link and the compiled class. But we need to get the compile class path here so link mapping you need to give a keyword of some LED and fast. Again the same class but which will help to communicate and give the link from sublet to back to the Soviet menu is communicating from this theme and to suddenly and welcome finalist list is your first smile from there. The request will pass or stopped working in this area. So this is what the application looks like for the solid and this is how it is written. If you want to see the execution so let's see the very first of that application. There are few things we need to have in our system in and said get the set up ready fast i.e. E for that coding which is which helps to write the code and make the object number two. We need the server application server or web server has to be configured and Java of course. So I have created my best web app so let app as I mention and that it is my select. You can see here this is my first ceramic glass file and when we compile it goes in the class file and that exists in the build in the eclipse ITC which I'm using. This is when my deployment descriptor exists. I'm defining all my sublet here. And next we have indexed on HD Emma. So and I have already configured my web server here so let's see how it goes. I show you the execution I have right. I did. I just draw. Right click on my application and goes to the run on server. I have to configure my server here and all I need to just select my application and see my server Stop it. And this is how my index dot is the emote contempt as hell no work testing app. And this is what my index Doc ECMO. But you can see the index start s.t. M.O. is not mentioned here. It's only the dust wrapped up and it this coming from the verb dot exam. So this is really important to understand the sun it is very efficient in respect to the security when ever we work in the servers we have to make sure our address should not be out. So here the source files is not mentioned anywhere in this back. So this is why the summit is ready efficient and important. So here I'm going to write down tech branch and OK so you can see. Welcome to selected crunch. Now if you'll see the part here the test web app is your web application which was mentioned in November. Example in the display name. Next we have so let which was a keyword we just mentioned again in the OPT OUT exhibit is stock from the index dot SD. Emma goes to the hello sort of list goes to the first set of it and from there again back to the barometer Angstrom there your indexed estimate from this but its display from here. But still it does not mention any in one user entered here. You see it still mentioning just the it. So this is one of the action which you see here. We have mentioned in an action this action has to map your supplement on the next. So let me and link and communicate this server. So this is on the ball. The demonstration of Sublet must help also let application important facts. So far we have learned all about the subject architectures of the API. Sort of like the lifecycle method and small demonstration. So let's see about important facts now. Should it be is a stateless program gone. That means once you create an initial instance offered to request or response you process it with the help of service method and you destroyed it. The state is closed. No you can not rule comeback or revert again back to the previous date. This is what the importance of to understand about the extra DP protocol. So whenever the solid create a thread and of instance of a request and process the request and provider response and after providing the response of the client and destroying the instance we can not recreate that particular request subnet is a server side Java program capable run in vim so so so it is very efficient sometimes when the requirement of an application is read you will have to write the Java program within the server posting platform accessible to do post and get type of data. All right. By. So we have to make sure when we use Duplass And when you duke it there is a difference between the Duke portion and you get that. You will learn when you actually work and develop an obligation in few chapters. Here in Sutherland API we have sublet exception which has to handle the exception it better by working with the verb application. So this is all about the Sunland API and the lifecycle method. Next up we are going to learn in detail about solid implementation and application development along with some homework. Thank you so much for watching. Take French and please subscribe to the channel and get updates for more upcoming videos. Let's make coding fun. Thank you.