by Dinesh Thakur Category: Basic Servlet Examples

We can gather the miscellaneous information from HttpRequest by calling various getxxx methods on request object as shown below.

* Use user-agent request header that holds browser software name as shown below.

  In service (--) method

 PW.println (“<br> <br> the current browser window” +req.getHeader (“user-agent”) )// request header name.

* The URL pattern of servlet program is technically called as servlet path.

//example request URL: http://localhost:2020/FolderName/PName? sno=11

PW.println (“<br> miscellaneous information of http request”);

//methods available in javax.Servlet.ServletRequest

PW.println (“<br> Request Content Length:” +req.getContentLength ());

//gives request data length in bytes like 345 bytes (if not known gives -1)

PW.println (“<br> request content type:” +req.getContentType ());

//gives request content like text/html (if not known gives null)

PW.println (“<br> request protocol:” +req.getProtocol ());

//gives http/1.1

PW.println (“<br> request scheme:” +req.getScheme ());

//gives Http

PW.println (“<br> request browser window machine IP address:” +req.getRemoteAddr ());


PW.println (“<br> browser window machine host name:” +req.getRemoteHost ());

//gives current computer name otherwise IP address

PW.println (“<br> browser window port no:” +req.getRemotePort ());

//gives 2922 for Netscape, 2926 for IE

PW.println (“<br> server name” +req.getServerName ());

//gives the domain name typed in the url like local host

PW.println (“<br> server port” +req.getServerPort ());

//gives 2020

//methods available in javax.Servlet.HttpServletRequest

PW.println (“<br> context path:” +req.getContextPath ());

//gives FolderName

PW.println (“<br> request method is:” +req.getMethod ());

//gives GET

PW.println (“<br> request path info is:” +req.getPathInfo ());

//gives additional information kept in request url (otherwise null)

PW.println (“<br> query string is:” +req.getQueryString ());

//gives sno=11

PW.println (“<br> request uri:” +req.getRequestURI ());

//gives /FolderName/PName

PW.println (“<br> request url:” +req.getRequestURL ());

//gives http://localhost:2020/ FolderName/PName

PW.println (“<br> servlet path:” +req.getServletPath ());

//gives /PName


* Servlet program can avoid browser dependent tags while generating html tags based    response if by knowing browser software name through the request header user-agent.

When web resource program (like servlet program) sends response to browser window the generated http response contain multiple details including response content. Those details can be remembered as SCH details.

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.