 Hello everyone. So, today in this video, let us see working with servlet using Eclipse. I am Professor Dattadri Ghandmal from Valchin Institute of Technology, Sallapur. Till now, we have seen how to write a servlet program. Now, here we let us see how to write a servlet program in Eclipse. That is what you will be able to understand after this video. So, what is the learning outcome of this video? At the end of this session, students will be able to demonstrate environment settings to run servlet program in Eclipse. So, students have to do some kind of settings so that servlet program will execute in Eclipse. Write a servlet program using Eclipse ID. So, once you do these settings, you will be able to write a servlet program and run a servlet program in Eclipse ID. There are some settings. Don't need to worry about it. I will tell you step by step. So, working with it will be very easy. Okay, let us go. Now, let's try a simple servlet program in Eclipse step by step. Now, first of all, you have to run an Eclipse ID. I am using your Eclipse Photon. Then, come down to File, click New, go to Dynamic Web Project. So, here we have Dynamic Web Project. In Dynamic Web Project, type the project name. I will give the project name as Test151. Just a random number. Test151. Okay. After that, click Next. Then, a source folder will be visible. Then, click Next. After that, here you click Generate Web.XML Deployment Descriptor. We have already seen what is Web.XML file, right? Then, click Finish. So, once you do this, a Test151 folder will be created. A project will be created, right? Then, in this particular project, there are various folders. We have seen the folder structure, right? In folder structure, just see one by one Java resources. What is there in Java resources? The folder is empty right now. After that, we have Web Content. In Web Content, we have an important folder called as Meta-INF. In Meta-INF, click Meta-INF. Here, we have a file called as Web.XML. We have already studied what is Web.XML, right? And LibFolder. So, all your resources will lie here in Web.INF folder, right? In source folder, you will create your own servlet file, okay? So, how to create a servlet file? Now, click on Project, this particular source file, New. I will select a file called as servlet, okay? So, this window will come. Here, you have to type your servlet name. What will be my class name? I will give it as demo servlet, which we have given in the previous video. Same file I will name I am using. Then, click Next. Here, there is a URL mapping slash demo servlet. Remember this. This URL mapping we have done in Web.XML file in the previous video. Now, we are in Eclipse. It gives me this dynamically. No need to do it. This comes automatically and I can use this slash demo servlet. You can change it whatever you want, okay? I will keep it same. Click Finish. Now, a file gets created, right? So, here we have a method called as do get. What is this do get? It is having two parameters, request and response. We have already studied this, right? I will, this is an auto-generated code by Eclipse. I will remove this, no need of it. We will write our own code, okay? Now, before that, you can see that there are some errors. HTTP servlet error and HTTP response error. Why these errors are coming? Yes, because the servlet API file is not present, okay? Now, when I go to, so to remove this, come down to project folder again. So, here you click on build path. Select build path, configure build path, then go to external JAR files. Add an external JAR file. Now, in external JAR file, you will go to the location ZAMP, where ZAMP was installed in C drive. In C drive, we will go to folder Tomcat, right? In Tomcat, I will go to lib. In lib, we have a file called as servlet API. I will select this file, open it. Now, servlet API.jar file is visible over here, okay? Then, apply. Servlet API will be applied and it will be added as an external library file. Then, apply and close. Now, here you can see those all errors are vanished, right? So, this is how we will import that particular JAR file, okay? In normal without Eclipse, we have already seen that we copy pasted a servlet API file and put it there, right? But here, what we will do is we have done it this way. We have a UI and we have added it through UI. Now, here I need to write a code. Do get what is the code? Response.setContent, okay? I response polling is wrong. Response.setContentType, setContent, just a minute, setContentType, response.setContentType, right? So, here I will select this. Here, I will mention that type of file, okay? I will give it as text slash html, okay? Text slash html because I am going to write servlet program in html inside java. So, your html code is embedded inside java file. This is what servlet is. We have studied in the previous video, right? Same thing we are doing in Eclipse. Now, here I need to have a printwriter, printwriter. I need to create its object, printwriter pw equal to, this is its object equal to response.getWriter, getWriter, okay? Now, here it is showing error at printwriter. Why? Because this import file is not there. I click on this particular icon. It will tell you the suggestion. So, just select import. It will get added, okay? So, remember that pw. You select on, you have to print it, right? So, pw.print. Here, you will write it as, now what? You will write here html file, right? So, I will write it in one line. No need to write in multiple file. So, it will be html file. Then, body of html. Just an html code, you have to write it here. So, I will write it fast h1. So, this is the three tags. I will write here hello servlet. Okay, hello servlet is there. After that, slash h1. You have to close all this slash body then slash html. So, done with it. I think it is fine now. html body h1, hello servlet h1 body. Okay, it is fine. Now, save this particular thing. If I try to run it, it won't run because a server is not there. To add a server, I will go to server tab. On server tab, click new, go to server and here, inside Apache, you take Tomcat 7.0 because I have installed 7.0 server. So, I will take this. Click next. So, already this is there. Finish. So, now Tomcat is started. Okay, then once this is done, I will go to test 151, click on new, sorry, click on run as and run on server. Now, here you can see Tomcat 7.0 server at localhost. Okay, take this and finish. Now, server has started and it will be, it is installed. You can see this. Now, html localhost 8080 test 151. Now, it is not able to locate it. So, we have given one mapping. I told you previously, what is that mapping? Demo servlet. Okay, if I put it, hello servlet. This is what our program is. Understood? It is very easy. Now, you look at this folder configuration, WebINF, web.xml file. Okay, this web.xml file, if you open, this is what web.xml file is. So, all mapping kind of thing that demo servlet is done here. Okay, now we will come back to our own ppt. Let's try to answer this, which basic library is required to be added for servlet program. So, which API you are using? Pause here and try to answer this. Servlet API.jar. How you have added this servlet API.jar? Here, test, right click, build path, configure build path, here you have added servlet API.jar file. Now, if you want any more changes, you will come down to source file and here I can change. If I want it in multiple lines, how I will write it in multiple lines, pw.print and I will distribute this particular code in multiple lines. So, I will put it here only body. Okay, I will close it here. Then, I will take this particular till h1. I will take it in one print line. Okay, I can take it here. Then, just a minute. So, I will take it here. I will take this particular last line. I need one more print line. Okay. So, what I do is pw.print. Okay. So, here copy paste it. So, here we already know that. Okay. So, this is how you can distribute your code on multiple lines. So, even you can write it in a single line. You can write it in multiple lines. This is also fine. So, now there is some error with the server. So, that is okay. You can restart it any number of times. Now, here once you do the changes, what has to be done? You come down to servers and restart it. Every time you make changes to your servlet file, you have to restart. Once you restart, then only you can run the file. Okay. So, now it is saying that server has started and synchronized. I hope this is clear, pretty clear. This is an interface ID, eclipse byte, photon I have used. Then API, servlet API jar has to be added. Add server has to be added. So, I told you how to add the server. Click on server, right click new and do that. So, these are simple. Once you do this, you can take more number of examples and do it. Okay. So, these are some of the references which I have referred. You can go through it. Okay. Thank you.