Using servlets for request and response management
Servlets are the core place to deal with requests and responses using Java EE. If you are still not familiar with it, know that even a JSP is nothing more than a way to build a servlet once the page is called.
This recipe will show you three features you can use when using servlets:
- Load on startup
- Parameterized servlets
- Asynchronous servlets
Getting ready
Start by adding the dependency to your project:
<dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>8.0</version> <scope>provided</scope> </dependency>
How to do it...
The load on startup servlet
Let's start with our servlet that will load on the server's start up:
@WebServlet(name = "LoadOnStartupServlet", urlPatterns = {"/LoadOnStartupServlet"}, loadOnStartup = 1) public class LoadOnStartupServlet extends HttpServlet { @Override public...