Eclipse IDE- Servlet Program

Steps:
You need to follow the following steps in order to create a Servlet in Eclipse:

  • Create a web project
  • Create a Servlet
  • Start Tomcat server and deploy project

Prerequisites:

  1. Eclipse IDE for Java EE Developers(download link)
  2. Apache Tomcat 6.0/7.0(download link , choose “32-bit/64-bit Windows Service Installer” to download from this link and install it by double click on the “.exe” file contained in archive)
  3. Once you are done with installation of Tomcat, remember not to run it at the same instance. As it will get conflicted later with Eclipse, when we deploy our project. Hence make sure that Apache services are stopped

Create a web project:
Select from the menu File –> New –> Dynamic Web Project.

Enter “FirstServlet” as your project name. Click on “NewRuntime” button and select “Apache Tomcat v6.0”.


Click “Next” button.

Click “Next” button.

Click on “Finish” button

Create a Servlet:
Select from the menu File –> New –> Servlet

Write “MyServlet” in the ‘Class Name’ field and then Click ‘Next’ button.

Now in case you want to specify deployment descriptor (web.xml), you can do this here and then Click ‘Next’ button.

Click on “Finish” button

Now you will get something like this

Now remove all that coding and replace it with

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class MyServlet extends HttpServlet
{
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		response.setContentType("text/html"); // informing the client that which format of data/response will be send
		PrintWriter out= response.getWriter(); 
		out.println("<hr>HELLO SERVLET</h3>"); // printing on the client

	}

}

Start Tomcat server and deploy project:
Right click on the project ‘FirstServlet’ and select from context menu ‘Run As’ –> ‘Run on Server’

Select the existing tomcat server
Click “Finish” button.
FirstServlet will get deployed.

OR
Press CTRL+F11, to run web application,

Click “Finish” button.
And you will see the output as

Advertisements

5 thoughts on “Eclipse IDE- Servlet Program

  1. Pingback: HTML + Servlet Program using Eclipse | UTLIMATECHANGE

  2. Pingback: HTML + Servlet Program using Eclipse | UTLIMATECHANGE

  3. Pingback: How to retrieve a form at Server end using Servlet | UTLIMATECHANGE

  4. Pingback: Database connection in Servlet | UTLIMATECHANGE

  5. Pingback: Retrieval of form fields name at Server end | UTLIMATECHANGE

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s