From the course: Jakarta EE Servlets
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Obtaining data from headers - Jakarta EE Tutorial
From the course: Jakarta EE Servlets
Obtaining data from headers
- [Instructor] When writing the logic for a servlet, it can be useful to obtain information that an upstream system or the client places into the headers of a request. Let's take a look at how this can be achieved by adding some content negotiation logic into our servlets, which is one of the many ways that we can use a header. So within our product servlet, I'm going to add a bit of logic that will retrieve a header from the HTTP servlet request. And then based upon the value of that header, we'll conditionally render the output using different formats like JSON or XML. So the first thing that we need to do is we need to obtain that header. The header is going to be the accept header. It's used by clients to indicate their preference for the response format. Using a MIME type, they can say always return the response in JSON or XML. So to get that header, we can invoke the getHeader method on the HTTP servlet request.…
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.
Contents
-
-
-
-
HTTP request messages5m 14s
-
(Locked)
Mapping requests to a Servlet4m 38s
-
(Locked)
Advanced Servlet mappings6m 4s
-
(Locked)
Request handler methods5m 19s
-
(Locked)
Obtaining data from query parameters8m
-
(Locked)
Obtaining data from the path4m 33s
-
(Locked)
Obtaining data from headers5m 53s
-
(Locked)
Obtaining form data from the request body5m 15s
-
(Locked)
Obtaining JSON data from the request body5m 46s
-
(Locked)
Challenge: Handling Servlet requests1m 32s
-
(Locked)
Solution: Handling Servlet requests6m 5s
-
-
-
-
-