JavaEE and Tomcat Basic Tutorial in Ubuntu 12.04

If you are interested in developing JavaEE with Linux and don’t want to use any IDE, or you are just looking around how JavaEE and Tomcat works with Ubuntu 12.04, well here is a fast and simple tutorial for you. Our object is to create a weight index calculator!

JavaEE and Tomcat Environment

First we will create the JavaEE development environment by installing JDK and Tomcat.

Next we will edit Tomcat configurations.

Add the following lines inside and edit your own USERNAME to the lines.

JavaEE File Structure in Tomcat

Create the jsp/ folder into your home folder.

Move inside the folder and create the basic file structure.

Minimal web.xml

Move to WEB-INF folder and edit configuration file for our JavaEE web application.

Here is the minimal web.xml file you can have, except I have included one servlet in here which we are going to use later. Paste this into the opened file.

JavaEE classes in Tomcat

We are going to create one class to help our application, these classes are also called beans.

We will create simple Java class.

Now we need to compile this file with javac.

Important note here! This is not a good style to compile the classes, you should have the .java files somewhere else and then just import the .class files here, because it is not secure to have original files here on the web interface. But since this is only a tutorial and we are learning here, this will do.

JSP files

Now we will create the .jsp files which will be shown to user as they browse our web application.

Add this code into the file.

And add another file

Starting Tomcat and testing the application

Now we have created all of our files and want to start our server and see the webpages. Type in the following command and restart the Tomcat server.

Open up web browser and go to http://localhost:8080/jsp/weight.jsp and you will see our application.
Tomcat Form

Give it your info and continue to the next page which will make use of our java class.

Tomcat Result

There are alot more in the world of JavaEE but this is was just a simple crash course into the subject using Ubuntu 12.04.