By
Vince Power

Most Popular Java Web Frameworks

As Java has evolved over the years, multiple attempts have been made to simplify development for various use cases. From official standards like Java Enterprise Edition, to community-driven frameworks, Java is continuing to prove itself to be adaptable and viable.

Our top list is based on usage from Hotframework.com's Java ranking and several other sources including blog posts and GitHub download numbers.

The top three are:

Other notable Java Web Frameworks:

Java Frameworks that are popular but not for the Web (We don’t want to forget them):

Spring

Project Site: https://spring.io/

Primary Sponsor: Pivotal Software

Spring is more than just a web framework. It is a complete programming model that is built on and with Java, starting with Spring Boot, which is a way to get a spring application up and running with minimal configuration and no application server required. At the other end of the spectrum is Spring Cloud, which is a combination of components that allows developers to build resilient and reliable cloud-native applications that leverage the latest distributed patterns like a microservices architecture — two examples include application security and batch processing.

There are many use cases for Spring, and with the introduction of Spring Boot, it is a great solution for companies that are moving towards containers as it greatly simplifies the components required to support the running application.

Getting started with Spring is as simple as going to Spring Initializr and selecting the build framework you desire and any and all the Spring projects you want included in the initial application. It will create the Maven or Gradle configuration and all the basic spring configuration required to start.

Creating a simple web application starting with Initializr (Figure 1):

Spring Initializr

… which will create a Zip file with the following files in it:

./mvnw.cmd
./pom.xml
./.gitignore
./.mvn/wrapper/maven-wrapper.properties
./.mvn/wrapper/maven-wrapper.jar
./mvnw
./src/test/java/com/example/demo/DemoApplicationTests.java
./src/main/resources/application.properties
./src/main/java/com/example/demo/DemoApplication.java

You need a Controller — src/main/java/com/example/demo/DemoController.java:

package com.example.demo;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class DemoController {

    @RequestMapping("/hello")
    public String hello() {
        return "hello";
    }

}

And a template file — src/main/resources/templates/hello.html

<!DOCTYPE HTML>
<html>
<head>
    <title>Hello World</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
    <p>Hello World</p>
</body>
</html>

JSF (Java Server Faces)

Project Site: http://www.oracle.com/technetwork/java/javaee/javaserverfaces-139869.html

Primary Sponsor: Oracle (soon to be a separate foundation)

JSF is a specification for displaying web user interfaces that is defined as part of the Java Platform, Enterprise Edition (JEE). JSF 1 was released in 2004, incorporated into JEE 5 and uses Java Server Pages (.jsp) as its templates. JSF 2 was released in 2009 as part of JEE 6, and leverages Facelets for templating and supports AJAX calls with a browser to allow modern web application lifecycles. JSF is component-based, allowing it to be expanded with additional components. IceFaces and MyFaces are examples of popular add-on components.

As JSF is part of the Java standard, it is popular with development teams that want to stick to published standards for increased portability across platforms. JSF also allows existing backend Java code to be extended with a web interface without having to refactor the base application by introducing a new framework.

A simple JSF application requires a Managed Bean, Facelet, and mapping the servlet.

helloworld.java

package helloworld;

import javax.faces.bean.ManagedBean;

@ManagedBean
public class HelloWorld {

    final String world = "Hello World!";

    public String getworld() {
        return world;
    }
}

helloworld.xhtml

<html lang="en"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html">
    <h:head>
        <title>Facelets Hello World</title>
    </h:head>
    <h:body>
        #{hello.world}
    </h:body>
</html>

web.xml

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>

GWT (Google Web Toolkit)

Project Site: http://www.gwtproject.org/

Primary Sponsor: Google

GWT is much like JSF in that it is strictly focused on building web interfaces. It is more popular than native JSF as it makes it easy to maintain complex JavaScript user interfaces with Java code. GWT has lost some of its popularity over the last couple of years as more development teams are pushing Java to the backend and having it expose REST APIs which are consumed by both native mobile apps and user interfaces built in Node.js, using frameworks like Angular.

A tutorial on how to build a simple GWT application can be found on its project site: Getting Started building a GWT app.

Conclusion

In summary, there are many viable Java Web Frameworks that can be used to address your needs. None of the top three are bad choices—It comes down to personal preference. Just be aware that once you commit to a framework and start to leverage its features, switching to another framework is not an insignificant amount of work.


If you haven’t already, signup for a 14-day free trial of Rollbar and let us help you take control of impactful Java errors. :-)

Join Our Community

Get the latest updates, tutorials and more, delivered to your inbox, once a month.

Comments