From the course: Jakarta EE Servlets
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Forwarding requests - Jakarta EE Tutorial
From the course: Jakarta EE Servlets
Forwarding requests
- [Instructor] Another technique that you'll find useful when working with servlets is forwarding. Forwarding allows a servlet to transfer or pass along a request to another servlet for processing. You can think of it kind of like a method call where one servlet calls another servlet in its processing. Here, let me show you what I mean. If we look at all of the handler methods in our application you'll notice that the end with this logic that handles the content negotiation. We check the accept header, and if it's XML, we return the product or products in that format to the client. Otherwise, we'll return them in a JSON format. And at the same time, we're setting our content type header. This bit of logic is at the end of all of our handler methods. We can also see it in the product servlet as well. So what we're going to do is forward request handling over to a new product response servlet that I've added to our project.…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.