Jakarta EE 9
Tested on JDK 11 LTS and Jetty 11
ee9exam
├── pom.xml
├── src
│ └── main
│ └── webapp
│ ├── WEB-INF
│ │ └── web.xml
│ └── index.jsp
pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>net.java_school</groupId> <artifactId>ee9exam</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <name>ee9exam Maven Webapp</name> <url>http://localhost:8080</url> <properties> <project.build.sourceEncoding>utf-8</project.build.sourceEncoding> <project.reporting.outputEncoding>utf-8</project.reporting.outputEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/jakarta.servlet/jakarta.servlet-api --> <dependency> <groupId>jakarta.servlet</groupId> <artifactId>jakarta.servlet-api</artifactId> <version>5.0.0</version> <scope>provided</scope> </dependency> </dependencies> <build> <finalName>ee9exam</finalName> <pluginManagement> <plugins> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>3.1.0</version> </plugin> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>3.0.2</version> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.1</version> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>3.2.2</version> </plugin> <plugin> <artifactId>maven-install-plugin</artifactId> <version>2.5.2</version> </plugin> <plugin> <artifactId>maven-deploy-plugin</artifactId> <version>2.8.2</version> </plugin> <!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-maven-plugin --> <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>11.0.12</version> </plugin> </plugins> </pluginManagement> </build> </project>
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> </web-app>
src/main/webapp/
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>jakartaEE 9 Examples</title> </head> <body> <c:choose> <c:when test="${empty param.name }"> <h4>Hello, World!</h4> </c:when> <c:otherwise> <h4>Hello, ${param.name }!</h4> </c:otherwise> </c:choose> </table> </body> </html>
mvn jetty:run
mkdir -p src/main/java/example vi src/main/java/example/InitParamServlet.java
Use jakarta.* instead of javax.* in the package names.
InitParamServlet.java
package example; import java.io.IOException; import java.io.PrintWriter; import jakarta.servlet.ServletConfig; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; public class InitParamServlet extends HttpServlet { private String url; private String user; private String passwd; private String driver; @Override public void init() throws ServletException { url = this.getInitParameter("url"); user = this.getInitParameter("user"); passwd = this.getInitParameter("passwd"); driver = this.getInitParameter("driver"); } @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { resp.setContentType("text/html; charset=UTF-8"); PrintWriter out = resp.getWriter(); out.println("url: " + url + "<br />"); out.println("user: " + user + "<br />"); out.println("passwd: " + passwd + "<br />"); out.println("driver: " + driver); } }
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> <servlet> <servlet-name>InitParamServlet</servlet-name> <servlet-class>example.InitParamServlet</servlet-class> <init-param> <param-name>driver</param-name> <param-value>oracle.jdbc.driver.OracleDriver</param-value> </init-param> <init-param> <param-name>url</param-name> <param-value>jdbc:oracle:thin:@127.0.0.1:1521:XE</param-value> </init-param> <init-param> <param-name>user</param-name> <param-value>scott</param-value> </init-param> <init-param> <param-name>passwd</param-name> <param-value>tiger</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>InitParamServlet</servlet-name> <url-pattern>/initParam</url-pattern> </servlet-mapping> </web-app>
mvn jetty:run
http://localhost:8080/initParam
Java EE 7-8 in the Spring Framework 5.3.x line
Jakarta EE 9+ in the Spring Framework 6 line
Spring Framework 6 based applications will require a minimum of JDK 17 at runtime, as well as a minimum of Tomcat 10/Jetty 11.
Migrating the book source to Jakarta EE 9
Test: JDK 17, Jetty 11, Spring 6, Spring-Security 6, Servlet 3 File Upload, DBCP2, MyBatis 3.5.x, Hibernate Validator 8
Source: https://github.com/kimjonghoon/JavaWebProgramming2
How to run
Open the log4j2.xml file in the src/main/resources folder and modify the log file path to match your system.
Open the WebContants.java in the net.java_school.commons package and modify the upload directory to match your system.
After stopping Tomcat, run the following:
mvn jetty:run