In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how Servlet reads request headers. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Read request headers in Servlet
It is very convenient to read HTTP headers in Servlet, as long as you call the getHeader method of HttpServletRequest. If the specified header information is provided in the customer request, getHeader returns the corresponding string; otherwise, it returns null. Some header information is often used, and they have special access methods: the getCookies method returns the contents of the Cookie header, which is parsed and stored in the array of Cookie objects. See the discussion in the Cookie section below; getAuthType and getRemoteUser methods read part of the Authorization header respectively; getDateHeader and getIntHeader methods read the specified header and then return the date value or integer value.
In addition to Servlet reading the specified headers, you can also use getHeaderNames to get an Enumeration object with all the header names in the request.
* in addition to viewing the request header information, we can also get some information from the request main command line. The getMethod method returns the request method, which is usually GET or POST, but it can also be HEAD, PUT, or DELETE. The getRequestURI method returns URI (URI is the part of the URL from the host and port to before the form data). GetRequestProtocol returns the third part of the request command, usually "HTTP/1.0" or "HTTP/1.1".
Example: output all request headers
The following Servlet example outputs all received request headers and their values in tabular form. In addition, the Servlet outputs three parts of the main request command: request method, URI, and protocol / version.
Package hall; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; public class ShowRequestHeaders extends HttpServlet {public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {response.setContentType ("text/html"); PrintWriter out = response.getWriter (); String title = "Show all request headers" Out.println (ServletUtilities.headWithTitle (title) + "\ n" + "+ title +"\ n "+" Request Method: "+ request.getMethod () +"\ n "+" RequestURI: "+ request.getRequestURI () +"\ n "+" Request Protocol: "+ request.getProtocol () +" public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {doGet (request, response) }} this is the end of the article on "how to read request headers for Servlet". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.