You are on page 1of 34

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/352785295

Installing Eclipse 2019-12-R and Tomcat 9.0 and Develop a Servlet

Technical Report · June 2021


DOI: 10.13140/RG.2.2.12123.08487

CITATIONS READS
0 553

2 authors:

Somasundaram Karuppanagounder Kalaiselvi Thiruvenkadam


Gandhigram Rural Institute Gandhigram Rural Institute
185 PUBLICATIONS 1,495 CITATIONS 166 PUBLICATIONS 1,105 CITATIONS

SEE PROFILE SEE PROFILE

All content following this page was uploaded by Somasundaram Karuppanagounder on 28 June 2021.

The user has requested enhancement of the downloaded file.


Installing Eclipse 2019-12-R and Tomcat 9.0 and Develop a Servlet
K.Somasundaram and T.Kalaiselvi
Department of Computer Science and Applications
Gandhigram Rural Institute, Gandhigram 624302, Tamil Nadu, India

ka.somasundaram@gmail.com, kalaiselvi.gri@gmail.com

Introduction

Servlet is an important component in developing Dynamic Web Applications. From the learners
point of view, it is essential to know how to install appropriate software tools to develop a servlet.
As servlet is a web component, it is to be placed in a web container to execute the servlets. Unlike
Java JDK where one can install and develop a Java application, servlet requires several supporting
tools to develop and run it on a application server. A typical environment to run a servlet is
shown in Fig.1. Several Integrated Development Environment (IDE) tools that combines, editors,
compilers, plugins, deployment tools, integrating with servers etc. have been developed.
NetBeans from Apache Foundation, Eclipse from Oracle are few of the popular IDEs .Further for
deployment of web components like Servlet, JSP XML documents, a web server is needed.
Tomcat from Apache Software foundation, Glassfish fro Oracle, Visual Studio from Microsoft etc.
are few of the popular web servers. These IDEs integrate the web servers into their working
environment and therefore becomes an application server. The current version of these tools
are too sophisticated , that it is too complex to configure them in the IDEs. From the student
point of view, it is necessary to have tools that can be easily installed and configured to develop
a servlet and other web components like JSP,XML, EJB etc.

1
Fig.1. A typical view of a web development and deployment environment.

In this technical report, we provide a step-by-step procedure how to install Eclipse-2019-12-R IDE
and Tomcat 9.0. Server and develop a servlet and other web components. Though Tomcat 10.0
is available, it is using jakarta.servlet package instead of the traditional javax.servlet package.
Though both have identical syntax and use, the currently (2021) available IDEs have not fully
implemented the jakarta.servlet. Many manipulations might be required to run them. Tomcat9.0
supports javax.servlet package and hence the examples in the textbooks can be implemented as
such without any trouble. Therefore, we have chosen Tomcat 9.0. The procedure is the same for
installing Eclipse-2021-03 with the latest Tomcat10.0.

It is also assumed that you have already installed at least JDK1.8 in your system, before
proceeding to the next steps.

2
1. Download the Apache Tomcat 9.0 .

In the list of software suitable for different platforms, select the installer version. We need the
Tomcat for windows64 bit platform. .

2. Install the Tomcat 9.0

Copy the downloaded file to a suitable folder of your choice. We have downloaded file
apache-tomcat-9.0.4.exe file from the download site.

3
This is an installer file. Double click the file , it will automatically install the Tomcat9.0 server in
your system. During installation, it will ask for user name and password. You may give the user
name as admin and password as rootroot to remember them easily. Otherwise you can give any
user name and password. Note them in your records, as you may need them latter for system
administration. After installation you can see the Tomcat 9.0 server running. You can test it by
opening the local host by entering the following URL in your web browser:

http://localhoast:8080/

You will get the following screen in your web browser indicating that you have successfully
installed Apache Tomcat 9.0 .

4
You can find the Tomcat 9.0 installation directory in C: drive as follows:

C: Program Files->Apache Software Foundation->Tomcat 9.0 with the following contents.

5
3. Stop the Tomcat server.

When the Tomcat was installed, it started running. Stop the running Tomcat server before you
plug it into Eclipse IDE. You can stop the Tomcat server by following the steps given below.

i. Get the Windows Control Panel.

ii. From the Control Panel select : System and Security

6
iii. From System and Security, select : Administrative Tools

iv. From Administrative Tools : double click Services

7
v. From services select Apache Tomcat 9.0

After selection, you will find the status of the Tomcat 9.0 server. It is running. Therefore,
you can Stop it or Restart it. Now select Stop. The Tomcat 9.0 server will be stopped.
Once you have stopped, you can see the status of the Tomcat as:

8
4. Download Eclipse 2019-12-R

You can download Eclipse 2019-12-R from the following link:

https://www.eclipse.org/downloads/packages/release/2019-12/r

Download Eclipse IDE for Enterprise Java Developers for Windows x86-64

9
4.1 Unzip the file

After downloading, copy it a suitable directory and unzip it.

Inside the unzipped folder, you will find another folder eclipse. Inside the eclipse folder, the
following files and folders can be found.

The file eclipse.exe with a logo is the file one has to double click to launch the Eclipse. Unlike
other IDEs, this IDE is not installed, but is to be launched each time you need it to run. You can
also create a desktop short cut by right clicking on the icon and Send to option.

10
4.2 Launching the Eclipse

Double click Eclipse icon (eclipse.exe) in the folder. It will start launching. First, you will get the
following Eclipse start up logo.

The eclipse launcher screen then will appear. It will ask you to select a workspace directory. You
can choose any drive, like D, E,F . Then click the Launch button.

11
After launching, you will get the starting screen with the green progress bar as follows:

Finally, the Welcome page of Eclipse will appear as follows.

12
Now the IDE is ready for use. Before you create any Project, you need to pug-in the Tomcat 9.0
server in the Eclipse IDE. After closing the Welcome window, you will get a Project Explorer
window

13
At the bottom of the Eclipse main window, there is a button Servers. Click the Servers button.

You will get a new window as follows.

A message will appear at the bottom of the window as:

No Severs are available. Click this link to create a new server.

4.3 Set the Sever

Click that link. A Define a New Server window will appear.

14
Wait for the system to populate the possible types of servers that are available in the package..
Look at the bottom corner of the main window, where you can see the progress in green color.
Out of several options, you will get Apache as one of the options.

Select the Apache folder in the window.

You will find options from Tomcat Server3.2 to Tomcat Server 9.0. Select Tomcat Server 9.0.

After selection you will get a new window as:

15
After selection of Tomcat 9.0, you will find that the two fields in the window are automatically
filled:

Servers host name: localhost

Servers Name: Tomcat v9.0 at localhost.

Now click Next . You will get a screen as follows:

16
Now it is asking for the Tomcat 9.0 installation directory. Using Browse option, search in the C:
drive and locate the installation directory (see Step-1) of Tomcat 9.0.

After locating the Tomcat 9.0 folder, select Select Folder button. If your selection is correct, then
you will get a new window as follows:

17
Now click Finish button. You will get a new window as follows:

You will find two changes in the main window.

In the Project Explorer window, a new folder Servers will appear.

At the bottom, you will find under Servers option the following message:

Tomcat v9.0 Server at localhost[Stopped Republish].

Now the installation of the server is over.

4.4 Creating Project folder.

One need to create a Project folder and then create the other application programs under that
Project. We want to create a servlet and run.

18
From File menu, select new and Dynamic Web Project. You will get a new window as follows.

After the selection of the Project, you will get new window as follows.

For Project Name, you can type any name you like. We will give it as Demoweb.

19
After filling the Project name as Demoweb, select Finish button. You will get a new window, with
Project explorer and other windows.

20
In the Project Explorer window, you will get a folder Demoweb.

4.5 Creating the servlet.

From File menu, select new and select servlet

You will get the Create Servlet window.

21
In this Create Servlet window, you need to fill two items.

Java Package: Give a name for the package in which the current servlet will be packaged. We give
it as servpack.

Class Name: Here you need to give a class name for the servlet. We give it as Welcome

After filling the two items, click Finish button and a skeleton of the servlet will be generated
automatically by the IDE as given below. All the imports, the annotation
((@WebServlet("/Welcome")), the doGet() and doPost() methods are inserted by default.

22
Since we are going to make simple servlet, which will give a welcome note, we only need one of
the servlet methods, either doGet() or doPost() method. We retain doGet() method and delete
the doPost() method. Then we insert the following java code to generate a HTML file that will be
executed by the client browser inside doGet() method and delete the other items.

response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.printf("<html>");
out.printf("<head><title>First Servlet</title></head>");
out.printf("<body>");
out.printf("<h1>Servlet Programming - An Example</h1>");
out.printf("</body>");
out.printf("</html>");

23
Since PrinterWriter is of OutputStream type, we need to import java.io package additionally in
the default program.
Finally, the whole servlet Welcome.java will be as follows.

package servpack;

import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/Welcome")
public class Welcome extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.printf("<html>");
out.printf("<head><title>First Servlet</title></head>");
out.printf("<body>");
out.printf("<h1>Servlet Programming - An Example</h1>");
out.printf("</body>");
out.printf("</html>");
}
}

24
After doing the editing of the program, right click and save the program.

4.6 Set a Web Browser.


All the output of the servlet will appear as HTML output in the client and therefore a web browser
is needed to execute it. If you do not specify any browser, the built-in browser will be used by
the IDE of the output. If you wish, you can choose an external browser like IE or Chrome or
Firefox. We are using Firefox. It is set from the Window menu in the main Eclipse window as:

Then right click in the Welcome.java program file and run the program as:

25
Select : 1Run on Server option. You will get the following window asking for the confirmation of
using the Tomcat9.0 server.

Click Finish button and you will get the problem message as:

26
Under Sever menu at the bottom as:

Tomcat v9.0 Server at localhost [Stopped, Synchronized].

Now click on the Details button in the error window. You will get the details of the problem as:

4.7 Correct the Port entry problem

The problem message says that one or more of the ports are invalid. Now press Ok and close the
Problem Occurred window. To correct the problem, double click on the Tomcat v9.0 sever at
localhost at the bottom of the main window. You will get the following screen.

27
Now you edit it. For the empty Tomcat admin port, you enter 8085 as port number.

After entering the port number, save the file and close the Overview window.

Now again run the program and you will get the output in the Firefox browser as given below.

28
You have now successfully installed the Tomcat9.0 server, Eclipse-2019-12-R and run a sample
servlet program.

To run the program you can use the Run icon in the main window. You can learn more when you
start using the Eclipse.

4.8 Create client –Sever programs

Now we will create a HTML file to be run at the client side. In this HTML we will give the name
,place ,district and state of the user as input and the servlet in the sever will echo the details back
to the client. So it requires two programs:

i. A HTML file with form at the client side


ii. A servlet at the server side to get the inputs from the client and return the same to the
client.

29
i. HTML document.: gethtml.html

<!-
Authors: K.Somasundaram and T.Kalaiselvi
e-mail: ka.somasundaram@gmail.com, kalaiselvi.gri@gmail.com
->
<!DOCTYPE html>
<HTML>
<HEAD>
<TITLE>Welcome</TITLE>
</HEAD>
<BODY>
<H1>HTML FORM WITH GET METHOD</H1>
<FORM METHOD="GET" ACTION="Myname">
<p> Please provide the following details</p>
<p> Name :<INPUT TYPE="text" NAME="name"></p>
<p> Place:<INPUT TYPE="text" NAME="place"></p>
<p> District:<INPUT TYPE="text" NAME="district"></p>
<p> State:<INPUT TYPE="text" NAME="state"></p>
<INPUT TYPE="SUBMIT" VALUE="Submit">
</FORM>
</BODY>
</HTML>

ii.Servlet :Myname.java

/* This program illustrates how a GET type request


from a client is serviced by a servlet. The request
is accompanied by four values of four parameters,
name, place, district and state. This servlet reads
the data and sends them back to the client as a response.
Authors: K.Somasundaram and T.Kalaiselvi
e-mail: ka.somasundaram@gmail.com, kalaiselvi.gri@gmail.com
*/

package servpack;

import java.io.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

30
@WebServlet("/Myname")

public class Myname extends HttpServlet {


private static final long serialVersionUID = 1L;

public void doGet(HttpServletRequest req, HttpServletResponse res) throws


IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
// Get the name parameter
String name = req.getParameter("name");
// Get the place parameter
String place = req.getParameter("place");
// Get the district parameter
String district = req.getParameter("district");
// Get the state parameter
String state = req.getParameter("state");
out.format("<html>");
out.printf("<head><title>" + name + "s Response</title></head>\n");
out.printf("<body>\n");
out.printf("<h1>Welcome " + name + "</h1>\n");
out.printf("<h2>You are from " + place + "\n");
out.printf(" which is in " + district + " District of\n");
out.printf(state + " in India. Great to meet you.</h2>\n");
out.printf("</body>\n");
out.printf("</html>\n");
}
}

First run the client side program gethtml.html. You will get the following input window:

31
Give the Inputs at client side by filling the above form generated by gethtml.html.

When you click the Submit button, you will get the following response from the sever side
(Myname.java):

32
--------------------x x x x x x x-------------------

33

View publication stats

You might also like