Register Login
Internet / AI Technology University (ITU/AITU)





|

Top Links: >> 80. Technology >> Internet Technology Summit Program >> 4. Web Apps Frameworks >> 4.3. Servlets and Java Server Pages
Current Topic: 4.3.1. Application Servers - Tomcat
You have a privilege to create a quiz (QnA) related to this subject and obtain creativity score...
4.3.1. Application Servers - Tomcat

Application servers allow running web applications and also provide necessary support for creating Web Apps. According to Java Enterprise Edition (JEE) blueprints, Java EE application servers must provide system services in open, industry standards. That allows the application developers developing programs according to the Java EE specification and not according to the proprietary application servers.

What are the main services supported by the application servers?

First of all there must be HTTP service support to allow web clients (browsers) to send web requests for services. So, an application server must include a Web Server.

All JEE application servers support Java Servlets and JSPs. As we learned before Java Servets are regular Java classes that provide a glue to a Web Server and take processing of Web Requests into their hands via doGet() and doPost() methods.

JEE application servers are capable to compile JSPs into Java Servets and execute them as regular Java classes. These two supporting mechanisms make possible Java-based web applications to run on the application servers.

Application servers are frameworks and containers for Java-based software components that represent web applications. JEE standards for application servers include requirements to manage security and database transactions. The application servers (AS) that support all JEE standard requirements, such as JBoss AS, IBM Web Sphere AS, Oracle WebLogic and GlassFish AS are JEE certified.

There are light-weight application servers, such as Apache Tomcat or Jetty that only provide very basic support for JSP and Servlets.

Apache Tomcat is the most popular application server, which is used by 33% of developers. The second popular server is JBoss – 26%. After these free open source containers, the followers are Oracle WebLogic - 10%, then IBM Web Sphere, Jetty, GlassFish and others…

We start with installation of Apache Tomcat.

installTomcat

Go to http://tomcat.apache.org – Downloads – Tomcat – select the latest version that fits your Operating System. For example, for Windows 8, 64 bit – pick up the 64-bit Windows Zip file.

Save the zip file in the c:/downloads – directory. Unzip this file into c: - drive and change the name of the directory from the long name with the version to a short name, such as c:/tomcat.

installTomcat

Explore the c:/tomcat - directory. Find the bin - directory with the script files, such as startup.bat, which can start the server or shutdown.bat, which can stop the server.

These scripts are supported by other scripts in the same directory.
Take a look in the lib directory. You will find many open source libraries, packaged as jar files there. Check the conf directory with important configuration files, such as server.xml and web.xml. We might tweak a line or two in the server.xml file to change the port of the web server. But this is later. We will talk about web.xml - file, which is according to JEE standard must be responsible for certain data.

And the most interesting place is the webapps - directory. This is the place for web applications. So far, you find there just one ROOT - directory with the default small application dedicated to Tomcat descriptions.

Open a command line window (cmd) and navigate to c:/tomcat/bin - directory.
Then enter: startup.bat or just startup.
This command will start the Tomcat server. Watch the output coming into the command window. The last lines will tell you that the server started listening at the port 8080.
Was it clear so far? Highlight the text in question Or


This means that your server side is ready to accept browser requests if they come to the port 8080.

Now you can open a browser and enter the following URL: http://localhost:8080.
Your request will hit the Tomcat server running on your local machine (localhost) on the port 8080.
You should see in response the page below, which is located in the c:/tomcat/webapps/ROOT/index.jsp – file. You can see the same output if you enter a complete URL: http://localhost:8080/index.jsp.

tomcatIndexPage

How does it work?

When a server takes a request from a browser, the server looks in the webapps directory for a proper application. Each application will form a directory with the application name.

The first URL just picks up the server host and port. By default this means that the Tomcat server will look in the ROOT directory. But we did not provide a file name to look for. How in the world the server picked up the index.jsp file?

The answer is in the c:/tomcat/conf/web.xml – file. At the end of the file you can see the section of welcome-file-list. In this section you find index.html and index.jsp files. These are the files that must be selected by default if no file names are provided.
The ROOT – directory includes index.jsp file, so this file will be displayed according to the welcome-file-list instructions.
Stop the Tomcat server by entering shutdown –S in the original command window in the c:/tomcat/bin – directory.
Another way to stop the server is to enter CTRL/C in the window with the server output.

The illustration below shows several steps to connect Eclipse with the Tomcat server.

tomcatInEclipse

Note:
We started working with an application server and we will include in the code in Eclipse new classes, such as HttpServletRequest, etc.
Keep in mind that application server library support these classes with multiple jar files in the lib directory. Let Eclipse to use this library! Here is how:
Right mouse click on the project name and select the Build Path option. Then, select Add Library and choose Server Runtime. Then, you can pick up a proper library, for example, Apache Tomcat.
The library will support the Servlet and JSP related classes, which you will need very soon.

Assignments:
1. Read about two most important configuration files: server.xml and web.xml
https://www.mulesoft.com/tcat/tomcat-configuration
2. Create two QnAs related to the subject (4.3.1.) and email to dean@ituniversity.us
3. Create two html files with the links to each other and the links to the index.jsp and place them into the c:/tomcat/webapps/ROOT – directory.
4. Modify ROOT/index.jsp – add the links to your html files
5. Start the Tomcat server and open a browser to see your html – files and index.jsp with the links to your files.
6. Email html and jsp files to dean@ituniversity.us

We invite you to create your own questions and answers (QnA) to increase your rank and win the Top Creativity Prize!

Topic Graph | Check Your Progress | Propose QnA | Have a question or comments for open discussion?

Have a suggestion? - shoot an email
Looking for something special? - Talk to AI
Read: IT of the future: AI and Semantic Cloud Architecture | Fixing Education
Do you want to move from theory to practice and become a magician? Learn and work with us at Internet Technology University (ITU) - JavaSchool.com.

Technology that we offer and How this works: English | Spanish | Russian | French

Internet Technology University | JavaSchool.com | Copyrights © Since 1997 | All Rights Reserved
Patents: US10956676, US7032006, US7774751, US7966093, US8051026, US8863234
Including conversational semantic decision support systems (CSDS) and bringing us closer to The message from 2040
Privacy Policy