How to create a start up class for Enterprise application servers

This article discusses how to create a start up class for a Java Enterprise / Jakarta EE compliant application server such as WildFly. There is no concept of start up class for an application server however you can deploy an application which contains a component bound to the deployment life cycle. For example, the javax.servlet.ServletContextListener … Read more

HelloWorld Servlet example

In this tutorial we will learn how to code and deploy an HelloWorld Servlet on the latest version of WildFly. A Java Servlet is a Java object that responds to HTTP requests while running inside a Web container. In terms of process, the browser sends an HTTP request to the Java web server. The web … Read more

Programming Jakarta Servlets

A Servlet is a web based component, managed by a container, that generates dynamic content. Currently, the latest release of Jakarta Servlets is 5.0 (September 7, 2020). Jakarta Servlet version 5.0 is only a change of namespaces. Thus, migrating a Servlet 4.0 project to Servlet 5.0 and above, requires the replacement of the namespace javax.* … Read more

Using Servlet 4.0 on WildFly

Server push is one core improvements in HTTP/2 which is included in Servlet 4.0 This feature aims aims at improving the perceived performance of the web browsing experience. Server push push is enabled to improved perceived browser performance because servers are in a much better position than clients to know what additional assets (such as … Read more

Uploading a File with a Servlet

Since Java EE 6 it is now easier to upload a File without the need of third party API. This can be done by setting the @MultipartConfig annotation within a Servlet. Let’s see a full example starting from an HTML page which contains a form with a “file” type field: <form action=”MyUploadServlet” enctype=”multipart/form-data” method=”POST”> <input … Read more

Intra-Servlet Communication

Sometimes you may need that a Servlet hands off its job to another Servlet or JSP. Intra Servlet communication can be done by means of a Dispatcher or by Redirecting the initial request. Dispatching is done by means of Dispatcher object which allows to complete the request without actually redirecting to user to another site, … Read more

Saving Session state with Cookies

Cookies are text data sent by server to the client to mantain information. The data sent gets saved at the client local machine. When client send request to server, it passes the cookies stored by the server in request header as in the following example: Set-Cookie: LSID=HYEGYUGe…Eaem_vYg;; Path=/application; Expires=Wed, 11-Mar-2014 21:21:01 GMT; Secure; HttpOnly … Read more

Dynamic Servlet Registration

One of the cool features introduces by Java EE 6 is Dynamic Registration of Servlets and Filters at application startup. This can be really useful if you are building your own framework but I guess for developers too can benefit from it. In order to do that, you can use some new methods introduced in … Read more

Rewrite: a Java EE URL rewriting solution

This tutorial will discuss about a cool open-source project named Rewrite which is an URL-rewriting solution for Servlet, JSF, and Java EE. Rewrite offers powerful configuration, flexible extensions, and framework integration.  In order to experience a basic usage of Rewrite you need to add the rewrite-servlet dependency to your Maven projects. Since we will test … Read more