2 Minutes To Code (β Version)

Java Servlets - 2 minute tutorial

Other objects/services provided by HttpServletRequest object

The other commonly used methods of the HttpServletRequest object are :

Method Description
Cookie[] getCookies() Gets all cookies sent by http client
String getContentType() Gets the content type sent by http client/browser in header
int getContentLength() Gets the length of request body sent by http client in header
String getCharacterEncoding() Gets the request's encoding sent by http client in header
String getContextPath() Gets the webapp's name that the http url points to
String getMethod() Gets the http method of the request made by client
String getServletPath() Returns the part of this request's URL that calls the servlet
String getQueryString() Gets the parameters contained in the request URL after the path
String getRequestURL() Gets the complete url of http request
String getRemoteAddr() Gets the ip of http client
String getRemoteHost() Gets the hostname of http client
int getRemotePort() Gets the tcp port of the http client machine used in the request
String getLocalAddr() Gets local(webserver's) ip address
String getServerName() Gets the local(webserver machine's) hostname
int getLocalPort() Gets the tcp port actually involved in http request, different from getServerPort()
int getServerPort() Gets the port on which webserver listens for incoming http request
Object getAttribute(String) Gets the attribute that jsp developer stores in request object
setAttribute(String, Object) Sets an object as an attribute in request object
removeAttribute(String) Removes attribute from request object.
Enumeration<String> getAttributeNames() Gets names of all attributes stored in the request scope