Client Request Servlet Demonstration

Good code is its own documentation. As you are about to add a comment, ask yourself, ‘How can I improve the code so that this comment isn’t needed?’ ~ Steve McConnell

When a browser requests for a web page, it sends lot of information to the web server which can not be read directly because this information travel as a part of header of HTTP request. Following is the example which uses getHeaderNames() method of HttpServletRequest to read the HTTP header
information. This method returns an Enumeration that contains the header information associated with the current HTTP request.

Once we have an Enumeration, we can loop down the Enumeration in the standard manner,
using hasMoreElements() method to determine when to stop and using nextElement() method to get each parameter name. Here is the code.

client

Once you are done creating the servlet with the above code, run it in you server and if everything goes right you should get the following result depending on your system.

header

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s