Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

How to run servlets on your hosting account

This guide explains what servlets are and how you set up the software that runs them.

How-To Guides2 min read11 steps

What is a servlet?

A servlet is a small Java program that runs on a web server. It answers requests from visitors and builds web pages. Java is a popular programming language.

Servlets need a servlet container. A container is a program that runs servlets, like a stage for actors. Apache Tomcat is the most common one.

Check your plan first

Normal shared hosting often does not include Java support. Ask Hostvento support whether Tomcat or Java hosting is available on your plan. On a VPS or dedicated server, you can install everything yourself. The steps below need root access.

Steps on a Linux VPS

  1. Log in to your server over SSH.
  2. Install Java.
sudo apt update
sudo apt install -y default-jdk

On CentOS or RHEL use sudo yum install -y java-11-openjdk-devel.

  1. Download Tomcat from the official Apache Tomcat website. Copy the link to the .tar.gz file in the "Binary Distributions" list.
  2. Download it with wget. Replace the link with the real one.
wget https://example.com/apache-tomcat.tar.gz
  1. Unpack it into /opt/tomcat.
sudo mkdir /opt/tomcat
sudo tar xzf apache-tomcat.tar.gz -C /opt/tomcat --strip-components=1

The strip option removes the extra top folder.

  1. Start Tomcat.
sudo /opt/tomcat/bin/startup.sh
  1. Open http://YOUR-SERVER-IP:8080 in your browser. You should see the Tomcat welcome page. If it does not load, open port 8080 in your firewall.

Deploy a servlet

  1. Package your servlet application as a WAR file. A WAR file is a single bundle that holds your whole Java web app.
  2. Copy the file into /opt/tomcat/webapps.
  3. Tomcat unpacks it by itself within a few seconds.
  4. Visit http://YOUR-SERVER-IP:8080/yourapp. The name matches your WAR file name.

Stop Tomcat

sudo /opt/tomcat/bin/shutdown.sh
Tip: Running Tomcat as root is risky. For a live site, create a normal user just for Tomcat and run it under that user.

Quick recap

  • A servlet is a Java program that builds web pages.
  • You need Java and a container such as Tomcat.
  • Shared plans may not allow this. Ask Hostvento support.
  • Deploy by copying a WAR file into webapps.