Transcript for:
Understanding Servlets and Their Containers

we should know about the servlet first okay before going to solids here we should know about dinner first so why you should know about container here satellites are server-side java classes these are server-side server-side java classes so these are server-side java classes what they will do they will read they are capable to read the data which is coming from browser so why these classes only capable to read the data why because your container will allow only sunlit classes to read the data which is coming from browser so you should talk about first container here to run certain loads to run salads what we required these server-side Java classes if you want to execute don't you require a solid container how to execute this classes how to execute how to run this classes how to run to run this sunlit classes we require a sunlit container to run sunlit classes it's required salads requires select classes requires requires servlet container select container so what this container will do we know what exactly the sunlit container will do whenever you submit your form data from a browser from a browser whenever you submit your form data let's if you have one browser here like Internet Explorer or if you have a browser here like a Chrome browser if you have a browser here so whenever you submit your form data from here whenever you submit your form data from here this data straightaway it will go to your server so this data when you submit to your server server need to respond so the data will send in the form of HTTP protocol from here we know HTTP protocol format it have two types of header and body through header we can send data through body also we can send it on okay if it is header we know we can call it as query string if it is a body we can call it as pelo okay so you can submit your data from browser in the form of HTTP protocol but who can understand this data here your container will understand which container will understand this data here servlet container your servlet container will accept first today's HTTP protocol data it will read your HTTP protocol data who will read the servlet classes required solid container so your servlet container first it will read your HTTP protocol data so in the form of what they will read this data once if it get HTTP protocol data they will make this HTTP protocol data in the form of Java Bean object so we can call it as HTTP request it will convert your data into HTTP servlet request object it will convert your data into httpservletrequest object whatever the history protocol data we are getting that data it will store in the form of httpservletrequest then later what it will do this httpservletrequest object it will forward to your sunlit classes here you can write servlet classes here you can write sunlit classes then whatever the HTTP protocol data we are submitting from here that data it will forward to your servlets who will do the job again solid container so the servlet container it will send the same data to your sunlit class it will send your data to sunlit class finally what we can do we can give response we can generate response here that response you should store in the form of HTTP response object HTTP servlet response we can store data finally in the form of HTTP protocol I mean we need to store in the form of HTTP servlet response again this response it will convert into HTTP protocol it will convert your response into HTTP protocol then the same response it will forward to the user finally ok so the data we need to get in the form of HTTP protocol into the container finally response also we need to give in the form of HTTP protocol only here and to read the data which is coming from browser which data it should be protocol data it will convert into httpservletrequest object so this data if you want to get here then your class should be a sublet class your class should be a servlet class or else your class can be a JSP page or else you can use cured filters using any one of these you can read data which is coming from your browser all these are same types certain lates or JSP czar filters okay so using any one of these you can read your data here but container need to do what container will read data okay fine it will read your history protocol data when I submit form data here container responsibilities are bought when I submit it when I submit from here as an user if you submit here as a end user as an user if you submit your form data from here so first ill is form data it will send to your server and server will get data in the form of HTTP protocol then later what it need to do it need to make the data in the form of HTTP servlet request data ok it will convert your data into httpservletrequest data later what it need to do it need to forward this data do select class right but which select class you have you can have any number of solid skier right one application can have any number of solid classes here so here you can have some ten number of solid skier so which is a late class need to respond for this data which sunlit classic need to execute I can have a Class B Class A Class B Class I can have many select classes here but when I submit this form data which servlet class me to execute is it me to execute all the satellites not required so it need to execute only particular solid let's say if you have here yes Earl it and if you have a be sunlit see sublet days are later which select class going to get that input httpservletrequest in good how it need to add I mean how it can navigate it your sunlit container whenever you submit your form data how it will decide whether a class RB class or C class or D class need to execute for this browser request it depends on your URL it depends on your URL let's say if all these sunlit classes are there in one application if that application name is if that application name is my app if that application name is my application if your application name is my application inside my application if you have classes a solid B solids is a light and desolate okay one sublet contain node in one solid container you can install in a number of applications so here my application name is my app so here application name application name is my app application name is equal to my app application name is my F so when I need to submit this data to that Maya how I need to enter my url here you need to enter URL here right so that URL we need to enter in the form of HTTP double double colon if that server is running in in your local machine if it is running in your local machine localhost if your IP if it is local machine then you can type here localhost okay if this server also there in same machine you can pass here localhost or if this browser is there in one machine and if the server is there in one machine you can pass that server IP address here okay usually in real-time browsers will exist in one machine and servers will exist in another mission at the time what we need to enter here instead of entering localhost we need to enter IP address here so general IP address default IP address 127 dot 0 dot 0 dot 1 or else you can use exact IP address if you don't know then you can go through this IP address ok so when you want to submit this data from here to here you need to pass HTTP colon double slash your IP address or else any domain name also we can enter here instead of using this localhost you can use domain name also here how I can use letter will say okay so here my machine IP address Colin and on which port this server running by default a tomcat server will run on a port number 0h0 so your port number you need to enter here age zero zero so up to here what it will understand where I enter this URL it can go to up to server but in that server it need to call a again application Maya so here again slash you need to enter your application name my app you need to enter your application in my app and in case if you require this page let's say if it is simple hello world page here I have a name along with the text box so this page from where it need to load on browser mission this page will exist are on server machine this page will exist actual page physical location is server so whatever the hello page you have here let's say if this page is hollow page in that other page if you required name and text box on one submit button here so this page need to design and we need to save here where we need to say inside my application itself let's say here if you have your page if you have your page here hollow dot HTML hollow dot HTML my page I have here now that hollow dot HTML page I want to load here so then what you should do again slash inside my application hollow dot HTML hello dot HTML so we are giving our page address we are giving we are giving here our application server here our applications are were solid container so solid container IP address and port number slash inside solid container my application name slash inside application my page name and if you click enter what happens this data it will send to your browser browsers what they will do whenever they try to load HTML data they will pass away all the tags and they will show the HTML content here so they will show our required xtml content here so then when I pass a name here when I pass it some name here no way and if I submit here what happens when I submit again this data it will convert into HTTP protocol and this data need to submit to whom the debt this rate I need to go to a sunlit class this rate I need to go to a sunlit class then however container will decide which select need to execute again it me to have a address right so for each satellite also you can configure one address here you can configure on wrong address okay for ASR let my address is my required address is slash hollow or as slash a my required address for a solid eight slash v4 b /b forestry / e 4 D / D these are my addresses ok address means along with your complete URL up to here / here so here my address sunlit addresses for this Hollow dot HTML we have address right so complete address we are passing here so then it will invoke your hallo dot HTML page but if you want to invoke your servlet you required again address right so that address if I use slash a means here before slash what it will append here before slash will append your complete path up to application name this path will append there so then your address of civilities sunlit yes and it is what HTTP colon double slash localhost:8080 slash my app slash yay so by using that address if I call then container will do what it will execute your sunlight class so where that address need to pass whenever I submit this form data to submit this data it need to have the address so where exactly that address we need to put while discussing in HTML I said one important tag is there the tag is contact in that form tag there is one attribute action in this action attribute you need to keep your URL HTTP colon double slash localhost colon 8080 row slash my app slash a /kr /b or /e here it is your action and here here your form content you can be keep here name input type text and a parameter name equal to some p1 and finally one submit button input' type submit' value submit or else you can keep anything here so while designing this form while designing this input form while designing this input form what you should keep here under action you are servlet address this is your sunlit address this is your sunlit address when you click on submit button it will generate address which address that HTTP address it will generate so here it will replace that address actually I have hollow dot HTML this hollow dot HTML when I click on the submit button it will erase this here and it will keep address /a then it will try to submit this data whatever the data we have here we know in the form of what the data it will submit HTTP protocol and in the sensory protocol will it put this data in guitar post I mean will it keep it in the header content or body content it depends on your form method by default form method is get so that your data it will go in the form of URL query string it will send you a data in the form of query string so that when I submit here a question mark your parameter name is what parameter name P P R P 1 equal to and the name whatever the name you are entering here naveen so this parameter P 1 and Naveen it will submit to your server then suffer need to execute what whatever the servlet configured by using this URL that Searle it classically to invoke so which are laid classically to execute a servlet so to execute a certain laid a cell it is a simple is it a simple like a form it's a simple Java class right this yes and it is a simple Java class how we can execute Java classes to execute a java class we required an object right we need to create object so that who need to create object now here I know the address for the traitorous I know the sunlit so then what I should do I need to create a object who will create that object your servlet container when satellite container will create object whenever first time user submits this address whenever user first time submits gives address if it is a first time request first request if it is your first request at the time of first request based on this address your sunlit container will prepare your select object actually all these classes are singleton class for singleton means only one object it will create so when that object it will create when first user submits this URL whenever the first user submits call for the address whenever first user submits keys address based on that address it will be mocha servlet class then that select class object it will create once after creation of your select object what it will do whatever the history of a request object a data to have here the data it will send to your object methods after creation of object we can call methods right inside sunlit so we need to write some methods so it will come into that method it will pass your HTTP servlet requested data okay who will do the job again you're solid container