Getting Started with Java EE — Part II: Basic Java Web App

Henry Delgado, BCS, MBA
4 min readJan 5, 2020

--

In Part I, we configured our local Java environment to run JBoss and WildFly. Now is time to create a basic Java web application that we can later run in our new WildFly server. You will not learn how to code in Java and this is not an advance Java web development topic. Simply, this is a continuation of our main topic: Getting Started with Java EE.

We will continue to use Eclipse IDE as in the previous part. Open Eclipse and let us get started. Disclaimer: this will not work if you have not configured your environment as in part I.

  • Create a new dynamic web page. The following example project name is called student-app. Click Next.
  • Select the sec path and click Remove. Then click the Add Folder button and add the following 2 paths (src/main/java and src/main/resources). Then click OK and Next to continue.
  • Click on Finish
  • Go to your src/main/java folder and right-click it to select New and then select Other as in the following screen:
  • Type servlet on the search and then select Servlet. Click Next to continue.
  • Create the Servlet using the wizard as the following screen. You can add your own Java package. Click Next.
  • Let us modify the URL mapping. Select /StudentServlet and click Edit. Rename to /Student. Click OK and Finish
  • You should see your new Servlet now. We will modify it in the next steps.
  • Right-click on the project (student-app) and select Properties. Go to Java Compiler and other right-hand side select the correct JDK version that is installed on your computer. By default, I had 11 and it caused issues when running the application. Avoid that by setting that proper version.

Finally, let us look at some code ✌. I have created some Java classes under src/main/java and a basic HTML page and JSP page under the WebContent folder.

  • Create the Person class

Person Class used to create a Student object

  • Create the Classroom class
  • Create a Servlet
  • Create the stylesheet under the WebContent folder:
  • Create the registration HTML page. I am using some basic HTML template with basic Bootstrapping.
  • Create the confirmation JSP page. The previous registration form will submit data to this JSP.
  • Right-click on the project and select Run as and then Run on Server. Navigate to your browser: http://localhost:8080/student-app/index.html. The final page looks like the following. Enter the first and last name and click on Sign in (Typo! That button should have said, Register).

If you made it this far, it means that your configuration is working and now you can continue to develop your custom java web pages using WildFly and Eclipse IDE.

What is Next?

This process can be a little tedious and time-consuming. We could create Docker containers and even work with Kubernetes.

These are some ideas:

  • Create a Docker container from JBoss/WildFly image. You could customize and it and extend it to use your Docker image.
  • You could run your existing WAR files on the Docker container with JBoss/WildFly image. Or you could work directly on the docker container for developing purposes.
  • We would need to work/develop directly on the container to prevent repeating all the Java EE configuration process.

I will be working on using this small project on Docker and Kubernetes. I look forward to sharing some of that experience.

Please leave your feedback or suggestions for alternatives based on your experience. I am interested in reading from your experience using Docker containers with Java EE applications.

I created a blog on how to create a Docker container based on a JBoss/WildFly Docker image to run replicate our environment and run our Java web application. View Blog

--

--

Henry Delgado, BCS, MBA

A passionate software developer eager to learn, evaluate and share!