 Hello everyone, so in the previous video we have seen introduction to servlet. Now let us see with working with servlet, let us see a practical example how to do a program in servlet. I am Professor Dattadri Kanmal from Valchian Institute of Technology, Solapur. So let us begin with this particular video working with servlet. So what students will be able to understand after this video, they will be able to identify various servlet API demonstrate simple program using servlet. So these two things are the outcome of this particular video. Let us quickly begin with servlet API. So what is servlet API? Servlet API is nothing but a package used for creating a program in servlet. So it's a package. So what is package? Package is nothing but which is collection of classes and interfaces in short. So now there are two servlet packages, one is javax.servlet.star and second one is javax.servlet.http.star. So these two packages, so why this servlet.star is going to, where it is going to be used? It is going to be used for any protocol, not to any specific protocol, it can be used to any protocol, may be HTTP, FTP and so on, whereas javax.servlet.http protocol, this particular package we are going to use only specific to HTTP protocol. So whenever I'm interested in HTTP protocol, I'll be using this particular package, okay? I think this slide makes sense, javax.servlet.star and javax.servlet.http.star. These two packages we have in servlet API. Next, what we have in javax.servlet package, we are going to see various interfaces present inside javax.servlet package, so these are all the interfaces present inside javax.servlet package. So what are the servlet, servlet request, servlet response, servlet config, context and so on. These all 14 interfaces we have inside javax.servlet package. Similarly, classes inside javax.servlet package, these are the various classes present inside javax.servlet package, generic servlet, servlet input stream and so on. So these are 11 classes present inside javax.servlet package. So basically a package contains classes and interfaces. So we have seen interfaces and now we are seeing classes. Next moving on to next package, javax.servlet.http package. What are the interfaces present inside this particular package? These are they are specific to HTTP. So they are prefixed with HTTP, HTTP servlet request, HTTP servlet response and so on. You can pause anytime and make a note of this particular interfaces and list of interfaces. Next classes in javax.servlet.http, these are the classes inside it, HTTP servlet, cookies, request wrapper, response wrapper and so on. So based on need, we will be using those classes. So these are all ready made classes and interfaces which are present inside API, which help us to do the servlet program. Next over here I request you to pause the video and try to list down servlet API. So just pause for some time, rewind the video and answer this particular question, list down servlet API. Okay, welcome back. So answer for this particular question is javax.servlet.star and javax.servlet.http.star. So these two packages or two APIs we have inside servlet API. Okay, next directory structure of servlet, very, very important slide. So directory structure, when you are creating a servlet program, you cannot directly write a .servlet file and do it. Here we have to follow structure, web app, inside web app we have a web.infolder, inside web.infolder we have a classes folder and lib folder. Inside classes we have a class files and inside web.infolder we have web.xml. Make a note of this, green color indicates folder and orange color indicates files. Web.xml is also a file. So anything resources you have, you directly can keep inside web app root directory. Please make a note of this. We'll start with, quickly start with actual program. So moving on to, we need a servlet file, right? So for that, let's go with servlet program. I have already created a demo servlet program. You can make a note of this demo servlet program. It's a demo servlet.java file. You can directly copy paste this particular java file, type as it is and let's say I want to, I'll copy this particular java file into one folder. Let's say I'll copy this into eDrive. Now I need to compile this particular thing. So come to command prompt and go to eDrive, java c demo servlet.java file. Demo servlet.java file, compile. So once you compile a demo servlet.class file will get created. So here demo servlet.class file is created. Now take this particular file and where you will paste it. So we have seen here in the directory structure, it should be inside web app and inside classes. So before that, we'll come down to zam folder. So I'm using here zam. So come down to zam and go to tomcat.insidewebapps. You create one folder. Let's say I'll create one folder, test123. In test123, inside it I need one more folder. I need webnf. Inside it, I need one more folder called as classes. Inside these classes, I'll paste that class file. So all class files will reside inside classes folder. This is clear. Then one more file is there, web.xml, important file. So I'll just, I have already web.xml file, copy this web.xml file and come down to that particular folder, test123, inside webnf, you paste it. So what is there in the web.xml file? Let us see, open with notepad. So this is what we have in web.xml file. What web.xml file is having? It is having a servlet class. What is a servlet class? Our servlet class is demo servlet, right? And servlet name. What is servlet name here? I am giving some dummy name x, y, z. That doesn't matter. It should be same up and down because it's a mapping. Second thing, URL pattern. It will call with that particular URL pattern. So I want this particular page to open with welcome, fine? So first of all, we'll see how to run it. So come, come down to XAM, XAM control panel and here we have Tomcat service. Start this Tomcat service and I have already started it. You can start it. Once it gets started, go to a web browser, I'll go to Google Chrome. Here you type localhost, okay? Once this localhost is, that means when you can see this piece, that means it is running. Here slash test123 slash welcome. Now this is welcome to first servlet. That means we have successfully executed it. So coming back to demo servlet, what we have written? I'll go to eDrive. Here we have a file called demo servlet. What we have written here? Here we have written doget. Inside doget, there are two parameters for it. As we have seen in the previous video, for every servlet, there is a request and we have a response back, right? Now here HTML code is embedded inside Java, that is servlet. So here HTML code you will write inside Java file. So here printwriter is a class for which I've created an object PW. Now println. So this is what printwriter is going to do. It is going to write as it is what we are doing in HTML. So here HTML, simple HTML file, HTML body. Welcome to first servlet. If you want something else, you can make a change over here. And copy all your HTML file over inside this println, pw.println, and it will execute. Understand important things to note down here is javx.serlet.http package I've used, servlet.star I've used, and jav.io star. I owe why, because I'm using printwriter. Make sense? Next, web.xml. I already told you what is web.xml. See, if you're not able to execute this when you are trying to compile this particular file, demo servlet, and you face problem, in that case, you will face a problem that compiler is not able to locate surlet.http package. When this error will come to resolve this error, you come down to Tomcat. Where is your Tomcat inside xam? There is a Tomcat folder, right? Inside Tomcat, there is a lib. In lib, you have surletapi.jar. This is what we have seen. This surletapi.jar contains all interfaces and classes. So what you will do? Copy this particular surletapi.jar file, and come to C, then program files, java, jdk, jre, lib, insidelib, ext. Inside ext, you will paste it. I've already pasted, surletapi. If you get an error of surletapi, you will do this thing. And definitely you'll get this error. You have to do this step. Okay? I think it is very clear now. Okay? So these are some of my references which I've used to create this video. I hope you understood. Thank you.