Using servlet for request and response management
The Servlet API was created even before Java EE exists—actually before J2EE existed! It became part of EE in J2EE 1.2 (Servlet 2.2) in 1999.
This is a powerful tool to deal with a request/response context and this recipe will show you an example of how to do it.
Getting ready
Let's add our dependencies:
<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>4.0.0-b05</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax</groupId> <artifactId>javaee-web-api</artifactId> <version>7.0</version> <scope>provided</scope> </dependency>
How to do it...
- Let's create a
User
class for our recipe:
public class User { private String name; private...