Introduction To Tomcat Server - Notes Lyst7111
Introduction To Tomcat Server - Notes Lyst7111
In the previous session we had seen the need of web applications, now let us see the difference
between Stand Alone Applications and Web Applications through an example-
Let us assume that a developer has developed a web application called “Foodiezzz” and all the
front end(HTML files), back end(Java files) and database are present in his computer where he
can compile and execute the program and start using the application.
But if you want to use the application in your system, then you have to download and install the
entire source code(front end, back end and database) in your computer, compile and execute it.
Now this application would be a Stand Alone Application and not a Web Application. But the
biggest disadvantage would be that the entire application should be present in the computer, if
you want to access the application but in real life such applications would be a huge application
with millions of lines of code and it would be impractical to download such huge application so
the companies which develop the applications should take this burden and now the customers
(client) should be able to send a request and now the based on the type of request,
automatically compilation should happen in the developer’s computer and whatever is being
requested for should be executed and the output should be displayed in the client’s computer.
And such an application is called Web Application.
Web applications should be stored in a special type of computer known as Server Computer.
User will have a browser installed in their computer and with the help of internet can send the
request to the server computer and now the server computer should recognise the type of
request and send the appropriate file as response
Any computer can be used as a server computer and for that we have to install a software
called Server software and there are many options available in the market-
And we will be using Apache Tomcat server for two main reasons-
● Open Source
● Free of cost
The most important part of a server software is called Web Container and A web
container is the component of a web server that interacts with Java servlets.Inside
this container we have to place all the files which must accept a request and send back
the response.
Let us see how to install Apache Tomcat server -
1. Go to google and search “Apache Tomcat download” and click on the 1st link
2. We will be using Tomcat version 8. Click on Tomcat 8 and then click on zip file to
download
6. Click on “No servers are available. Click this link to create a new server...” link
7. Now select “Apache” in the pop up
8. Scroll down and click on “Tomcat v8.5 Server”
9. Click on Next and select the folder in which you have downloaded the tomcat
server.
10. Click on Finish.
Now let us create a web application from scratch. We will be creating Dynamic Web
project in Eclipse
Steps to create Dynamic Web Project:
1. Launch Eclipse and click on file and select “Dynamic Web Project”.
2. Set project name to “J2EE” and click on next
3. Click on Next
4. Click on Next and Click on Finish.
5. Right click on the project and click on new and select HTML file
6. Set the name as ‘exmp.html’ and click on Finish.
The HTML file is be present in WEB-INF folder and this is the project structure-
In our server computer we have installed Tomcat and every server has a web
container and Catalina is the name of the Tomcat server’s Web Container and
the port number of Catalina is 8080.
The dynamic web project which we have created is “J2EE” and this should be
loaded into the web container(Catalina) and only then the project is accessible to
the client and technically adding this project to Tomcat is called Deployment.
http://192.167.1.2:8080/J2EE/exmp.html
Where -
http: Protocol
192.167.1.2: IP address
8080: Port number
exmp.html: Resource(HTML file)
Example 2:
Whenever we enter a URL in our browser, then by default the Home page of that
particular web page will be displayed. But in our program if we just enter
“http://localhost:8080/J2EE”, we get the following error-
We don’t want such error messages to be displayed, instead if the user does not
request “exmp.html” then by default another html file should be displayed.
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Home Page</title>
</head>
<body>
<h3>A Web Application consists of 3 layers:</h3>
<ul>
<li>Front-End</li>
<li>Back-End</li>
<li>Database</li>
</ul>
</body>
</html>
Now, whenever user does not request explicitly for a file, then automatically the request
is sent to web.xml, in which we are redirecting to index.html