Hosting

How to deploy a JSP or servlet app (WAR file) on Tomcat hosting, step by step (2027)

6 min read By Cloud Ninza

College projects, internal tools and many business systems in India are JSP and servlet apps packaged as a WAR file. Here is how to put one live on Tomcat hosting, which Tomcat version it needs, and how to fix the errors people hit most.

In short To deploy a JSP or servlet application, build it as a WAR file (for example with mvn package), then upload the WAR to a Java hosting plan that runs Apache Tomcat. On Cloud Ninza Java plans (from ₹299 a month, billed yearly) you upload the .war into the app folder or deploy it from GitHub, and it runs at the root of your domain. Apps written for javax.servlet run on Tomcat 9 and apps written for jakarta.servlet on Tomcat 10.1 or 11; the version is chosen from your code, or set with the start command cn-tomcat 9, cn-tomcat 10.1 or cn-tomcat 11.

WAR, JSP, servlets and Tomcat in one minute

A servlet is a Java class that answers web requests. A JSP (JavaServer Page) is an HTML page with Java mixed in, which Tomcat turns into a servlet the first time it is opened. A WAR (web application archive) is a zip file with a fixed layout: your pages at the top, and a WEB-INF folder holding your compiled classes (WEB-INF/classes), the libraries you use (WEB-INF/lib) and, often, the settings file web.xml.

Apache Tomcat is the server that runs WAR files. Spring Boot apps usually carry their own Tomcat inside an executable JAR; classic JSP and servlet projects, Spring MVC apps built as a WAR, Struts apps and most college and internal projects need a separate Tomcat. That is what Java hosting with Tomcat gives you.

The one thing to get right: javax or jakarta

In 2020 the Java EE specifications moved to the Eclipse Foundation and were renamed Jakarta EE. From Jakarta EE 9 on, every package name changed from javax.servlet to jakarta.servlet. Tomcat followed: Tomcat 9 runs javax.servlet code; Tomcat 10.1 and 11 run only jakarta.servlet code.

That is the cause of the most common deployment failure. Deploy an older app on Tomcat 10 and it fails with ClassNotFoundException: javax.servlet.http.HttpServlet, or the JSP pages show errors about javax.servlet. Deploy a new jakarta app on Tomcat 9 and you get the same error the other way round.

  • Your imports start with javax.servlet, or web.xml mentions java.sun.com or xmlns.jcp.org: use Tomcat 9.
  • Your imports start with jakarta.servlet, or web.xml mentions jakarta.ee: use Tomcat 10.1, or Tomcat 11 on Java 17 or later.
  • On Cloud Ninza you do not have to decide: the app is read when it starts and run on Tomcat 9 or 10.1 accordingly. To choose yourself, set App settings → Start command to cn-tomcat 9, cn-tomcat 10.1 or cn-tomcat 11.

Step 1: Build the WAR

If the project uses Maven, check that pom.xml has <packaging>war</packaging>, then build it on your computer. The WAR appears in the target folder.

  • Maven: mvn -DskipTests package → target/yourapp.war
  • Gradle with the war plugin: ./gradlew war → build/libs/yourapp.war
  • Eclipse: right-click the project → Export → WAR file. NetBeans: Clean and Build, then look in the dist folder.
  • Compile for the Java version you will run. With Java 21 on the server, building with JDK 17 or 21 (or --release 17) is safe.

Keep database passwords out of the WAR. Read them from environment variables (System.getenv("DB_PASSWORD")) so the same file works on your computer and on the server, and nothing secret is inside the archive.

Step 2: Launch a Java app

In the dashboard, open Launch an app, choose the Java blueprint and the Java version: 21 is a good default, 17 for older Spring 5 apps, 11 only for apps that need it (Tomcat 11 needs 17 or later). Choose a plan by memory: Java is heavier than PHP, so each Java plan comes with its own app RAM allowance, from 768 MB on Starter to 4 GB on Pro.

Give it your domain, or a free cloudninza.in address to test first. A few minutes after payment the app answers with a placeholder page.

Step 3: Upload and start

Open the File manager. It opens in the app's folder, web/yourdomain/app. Upload your .war there (any name; ROOT.war is fine), delete the placeholder file CnPlaceholder.java if you like, and press Restart under App settings.

The app runs at the root of your domain: https://yourdomain.com/, not https://yourdomain.com/yourapp/. If your JSP pages link with a hard-coded context path, change them to use request.getContextPath() or relative links. An unpacked app (a folder with WEB-INF inside) works the same way.

Or deploy from GitHub

Connect your repository under Git deployments and choose the WAR on Tomcat preset in App settings. Every push to your branch then runs mvn package on the server, puts the new WAR live and checks that it answers; if it does not start, the previous release is put back automatically.

Step 4: Connect a database

Create a MariaDB, MySQL or PostgreSQL database under Databases. In App settings → Environment variables, add the connection details, for example DB_URL=jdbc:mysql://localhost:3306/youruser_shop, DB_USER and DB_PASSWORD, then restart. Use localhost as the host: the database is on the same server and never open to the internet.

Put the JDBC driver (mysql-connector-j, mariadb-java-client or postgresql) in your project's dependencies so it ends up in WEB-INF/lib. A database hosted elsewhere, such as Amazon RDS, works too with its own connection string.

Logs, HTTPS and the visitor's IP

Tomcat's messages and anything your app writes to System.out or a logger appear under App settings → Logs. Start there whenever the domain shows an error: the first lines after a restart say which Tomcat and Java version started, and a deployment error names the class or file that failed.

Visitors reach your app over HTTPS through the web server in front of Tomcat, which passes on the protocol and the visitor's address. request.isSecure() returns true for HTTPS visits and request.getRemoteAddr() returns the visitor's real IP, so redirects to https and login rate limits work as expected.

Errors you are most likely to see

These are the errors people hit most often, and what each one means:

  • ClassNotFoundException javax.servlet.*: a javax app on Tomcat 10 or 11. Set the start command to cn-tomcat 9.
  • jakarta.servlet cannot be resolved, or the app does not start on Tomcat 9: a jakarta app. Use cn-tomcat 10.1.
  • UnsupportedClassVersionError: the WAR was compiled for a newer Java than the server runs. Choose a newer Java version in App settings, or build with --release 17.
  • 404 on every page: the WAR has an extra folder level, or the app expects a context path. Open the WAR as a zip and check that WEB-INF is at the top.
  • OutOfMemoryError: the app needs more RAM than the plan allows. Java uses 70% of the plan's app RAM for its heap; upgrade to a bigger plan.
  • Cannot connect to the database: check the variables in App settings and that the JDBC URL uses localhost and the full database name with your account prefix.

When you need more than shared Java hosting

Shared Java plans suit most JSP and servlet apps: business portals, college projects, booking and billing systems with up to a few thousand users a day. For a heavy enterprise app, several apps that each need gigabytes of memory, or software that needs a specific application server such as WildFly or WebLogic, a cloud server with dedicated resources is the better fit, and we can quote one.

Key takeaways

The short version, for anyone skimming:

  • A WAR is a zip with your pages at the top and a WEB-INF folder; Apache Tomcat runs it.
  • javax.servlet apps need Tomcat 9; jakarta.servlet apps need Tomcat 10.1 or 11. Cloud Ninza picks the right one from your code, or you set it with cn-tomcat 9, 10.1 or 11.
  • Upload the .war into the app folder and restart, or deploy from GitHub with Maven; it runs at the root of your domain.
  • Keep database settings in environment variables, and read App settings → Logs when something fails.
  • Java plans start at ₹299 a month, billed yearly, with 768 MB of app RAM.
Host it with us

Java Hosting

Java hosting on cloud servers in India from ₹299 a month, billed yearly. Backups twice a day (12 AM and 12 PM), last 30 days kept — restore any date yourself from your dashboard, or make your own backup any time · Spam protection: hourly and daily email sending limits per project, and automatic pausing of spam-like sending, keep your domain and our mail servers trusted · OpenJDK 11, 17, 21 or 25.

Ready when you are

Hosting from ₹149 a month on servers in India

WordPress, static HTML, PHP, Node.js, Python and Java plans with free SSL and your choice of version. Create your account, pick a plan and pay by UPI, card or netbanking; your hosting is created automatically and you get your login by email, usually within minutes.

Questions

Questions on this topic

How do I deploy a WAR file on hosting?

Build the WAR (mvn package), upload it to the app folder of a Java hosting plan with Tomcat, and restart the app. On Cloud Ninza it then runs at the root of your domain.

Which Tomcat version should I use?

Tomcat 9 for apps that use javax.servlet, Tomcat 10.1 or 11 for apps that use jakarta.servlet. Cloud Ninza chooses automatically from your code.

Can I host a JSP website in India?

Yes. Cloud Ninza Java plans run JSP and servlet apps on Apache Tomcat on servers in India, from ₹299 a month, billed yearly.

Why do I get ClassNotFoundException javax.servlet?

The app was written for javax.servlet but is running on Tomcat 10 or later, which only knows jakarta.servlet. Run it on Tomcat 9.

Can I use MySQL with my JSP app?

Yes. Create a MariaDB or MySQL database in the dashboard, add the JDBC driver to your project, and pass the connection details as environment variables.

Can I deploy from GitHub?

Yes. Connect the repository under Git deployments; each push builds the WAR with Maven and deploys it, with automatic rollback if it fails to start.

Does it support Spring MVC or Struts?

Yes, when packaged as a WAR they run on Tomcat like any servlet app. Spring Boot apps can also run as an executable JAR.

How much memory does a Java app get?

From 768 MB on Starter up to 4 GB on Pro, shared across the plan's apps. Java uses 70% of it for the heap.