For creating a Hello World Servlet Example using eclipse IDE with tomcat 7, you just need two things:
i) Download and install Eclipse IDE for Java EE developer.
ii) Download and install the Apache Tomcat server
Download Tomcat Server: Click here to download
After download and install Eclipse IDE for Java EE developer and Tomcat Server, you will be able to create Hello World Servlet Example using Eclipse IDE.
1) Create a Dynamic web project:
To create Dynamic web project open eclipse ide -> Go to menu -> New -> Dynamic web project.
Write your project name and click on next.
check on generate web.xml and click on finish button.
After clicking on the finish button, your Eclipse IDE will automatically create a dynamic web project as shown below.
2) Create a servlet class:
Once you create a dynamic web project your next step is to create a servlet class. right click on your project -> New -> ServletWrite your package name in java package field and class name in the class name field and click on next.
We can specify the URL mapping in the following screen(web.xml) and click on next.
Click on the finish button.
After clicking on the finish button, your Eclipse IDE will generate a servlet class based on the configuration provided in previous steps as shown below.
3) Write your custom code:
Write your code into doGet() method and call to setContentType() establishes the MIME types of the HTTP response.In this program,the MIME type is text/html.Next the getWriter() method obtains a PrintWriter.Then println() is used to write some HTML code as the HTTP response.Read more about HTTP Request Methods: HTTP Requests Methods
4) Run your Servlet Code:
To run your Servlet code right click on your project -> Run As -> 1 Run on Server.
Select the existing Tomcat Server and Click on the finish button.
5) The output on Browser.
Your Eclipse IDE will generate output on own browser and print "HELLO WORLD" on the browser.
You may also like:
JSP Life Cycle
MVC Architecture in JSP with Example
Custom Tags in JSP
Session Tracking in Servlet and its technique
Servlet Life Cycle in Java
How to create Hello World Servlet example using eclipse IDE with Tomcat 7?
Reviewed by Prashant Srivastava
on
October 13, 2018
Rating:
No comments: