Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
4.1 Reading Request Headers from Servlets
95
getContentType
The 
getContentType
 method returns the value of the 
Content Type
 header (as a 
String
). 
getDateHeader
 and 
getIntHeader
The 
getDateHeader
 and 
getIntHeader
 methods read the 
specified header and then convert them to 
Date
 and 
int
 values, 
respectively. 
getHeaderNames
Rather than looking up one particular header, you can use the 
getHeaderNames
 method to get an 
Enumeration
 of all header 
names received on this particular request. This capability is 
illustrated in Section 4.2 (Printing All Headers).
getHeaders
In most cases, each header name appears only once in the 
request. Occasionally, however, a header can appear multiple 
times, with each occurrence listing a separate value. 
Accept Language
 is one such example. If a header name is 
repeated in the request, version 2.1 servlets cannot access the 
later values without reading the raw input stream, since 
getHeader
 returns the value of the first occurrence of the 
header only. In version 2.2, however, 
getHeaders
 returns an 
Enumeration
 of the values of all occurrences of the header.
Finally, in addition to looking up the request headers, you can get informa 
tion on the main request line itself, also by means of methods in 
Http 
ServletRequest
. 
getMethod
The 
getMethod
 method returns the main request method 
(normally 
GET
 or 
POST
, but things like 
HEAD
, 
PUT
, and 
DELETE
are possible). 
getRequestURI
The 
getRequestURI
 method returns the part of the URL that 
comes after the host and port but before the form data. For 
example, for a URL of 
http://randomhost.com/servlet/search.BookSearch
, 
getRequestURI
 would return 
/servlet/search.BookSearch
.
getProtocol
Lastly, the 
getProtocol
 method returns the third part of the 
request line, which is generally 
HTTP/1.0
 or 
HTTP/1.1
. Servlets 
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

jsp web hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Jsp Web Hosting Cheapest Web Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved