Hi
We want to know the read request which come from the headers from servlet in java .
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Apr 11, 2012, 7:53 PM EDT
Reading HTTP request headers from a servlet
When a browser requests a web page, it generally sends some additional headers which specify things such as:
It's beyond the scope of this tutorial to give all the details of every possibly HTTP request header. And it's actually quite rare to need to read request headers. If necessary, it is recommended that you look at the HTTP protocol specification if you need more details. However, we'll look at a couple of useful cases here by way of example.
Reading a request header
Usually, we'll know the name of the request header that we want to read. In this case, it is a simple matter of calling getHeader() on the HttpServletRequest object that was passed to our doGet()/doPost() method. For example, here is how to read the user-agent header, which essentially tells us which browser (IE, Mozilla, Safari etc) and operating system is making the request:
public final void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String agent = req.getHeader("user-agent"); if (agent != null && agent.indexOf("MSIE") > -1) { // Internet Explorer mode } else { // Non-Internet Explorer mode } }Please refer the below links
http://www.javamex.com/tutorials/servlets/request_headers.shtml
http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/Servlet-Tutorial-Request-Headers.html
Thanks
Thanks