Рет қаралды 201
How to create Simple Web Application Using Servlet in Eclipse IDE
Step 1: Create a Dynamic web project
Enter the Project Name.
Check if the location where the project saves is correct.
Check if the Run time selected for the project is displaying. If you want to change any of the configurations for runtime, you can do by clicking Modify.
Click on Next.
The source folders on the build path and the classes folder will be displayed here.
Click on Next.
We can also generate a Deployment Descriptor - web.xml file to define the mappings between URL paths and the servlets to handle the requests with those paths. This can also be done using @WebServlet() annotation in the Servlet class.
In this video, we will be using annotation in our servlet class to map the URL path.
But for the demonstration purpose to show the web.xml file creation in the project, we will select the web.xml checkbox also.
Click on Finish.
Step 3: Create Servlet Class
To create a Servlet, go to folder New --Servlet.
It is a good practice to create Java classes inside Packages.
Enter the package name and Class name.
Click on Next.
Once we get the Get request from the browser, the do Get() method will be executed.
In the java.io package, Java provides a Print Writer class to print the formatted output to the text-output streams.
So, get the Print Writer object and print the Welcome Message.
Step 5: Run the Project
Right-click on the Project Run As -- Run on Server.