Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HTTP Protocol & Servlets

 
Gerardo Tagliani
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How could I get all the information (example below) sent by a client using servlets?

Example:
GET /index.html HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*
Accept-Language: pt-br
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Host: localhost
Connection: Keep-Alive
 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use request methods request.getHeaderNames() and request.getHeader(headerName).
 
Periakaruppan Thiagarajan
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getHeader(String name):
The method getHeader(String name) of request object is used to return the value of header given in request. The returned value of header is a string.

General Syntax:

request.getHeader("String")

In the above the returned value is a String.

For instance

String exfosys = request.getHeader("exforsys")

The above would retrieve the value of the HTTP header whose name is exforsys in JSP.

getHeaderNames():
The method getHeaderNames() of request object returns all the header names in the request. This method is therefore used to find the available headers. The value returned is as a enumerator of all header names.

General Syntax:

request.getHeaderNames();

In the above the returned value is an enumerator.

For example

Enumeration exforsys = request.getHeaderNames();

The above returns all header names under the enumerator exforsys.

Regards,
Pk
 
Gerardo Tagliani
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks people!

I will try!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic