Saturday, March 28, 2015

A detail about client request in JSP

A brief in JSP client request 


When a browser from the client side requests for a web page, it send lots of information to the web server which can not be read directly because this information travel as a part of header of HTTP request. Now this request are handled by important headers that is sent by our browser while sending the request.
Following are the important header information that comes from browser part .

Header
Description
Accept
This header says the MIME types that the browser or other clients can handle. Values of image/png or image/jpeg are the two most common possibilities.
Accept-Charset
This header says the character sets the browser can use to display the information. For example ISO-8859-1.
Accept-Encoding
This header talk about the types of encodings that the browser knows how to handle. Values of gzip or compress are the two most common possibilities.
Accept-Language
This header says the client's preferred languages in case the servlet can produce results in more than one language. For example en, en-us, ru, etc.
Authorization
This header is used by clients to identify themselves when accessing password-protected Web pages.
Connection
This header indicates whether the client can handle persistent HTTP connections. Persistent connections permit the client or other browser to retrieve multiple files with a single request. A value of Keep-Alivemeans that persistent connections should be used
Content-Length
This header is applicable only to POST requests and gives the size of the POST data in bytes.
Cookie
This header returns cookies to servers that previously sent them to the browser.
Host
This header specifies the host and port as given in the original URL.
If-Modified-Since
This header indicates that the client wants the page only if it has been changed after the specified date. The server sends a code, 304 which means Not Modified header if no newer result is available.
If-Unmodified-Since
This header is the reverse of If-Modified-Since; it specifies that the operation should succeed only if the document is older than the specified date.
Referer
This header indicates the URL of the referring Web page. For example, if you are at Web page 1 and click on a link to Web page 2, the URL of Web page 1 is included in the Referer header when the browser requests Web page 2.
User-Agent
This header find out the browser or other client making the request and can be used to return different content to different types of browsers

Example:

JSP File (client-request.jsp)
 <%@ page import="java.io.*,java.util.*" %>  
 <!DOCTYPE html>  
 <html>  
 <head>  
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>  
 <title>nirajanghimireyworkshop.blogspot.com</title>  
 </head>  
 <body>  
 <center>  
 <h2>HTTP Header Request Example</h2>  
 <table width="100%" border="1" align="center">  
 <trbgcolor="lightsalmon">  
 <th>Header Name</th><th>Header Value(s)</th>  
 </tr>  
 <%  
   Enumeration headerNames = request.getHeaderNames();  
 while(headerNames.hasMoreElements()) {  
    String paramName = (String)headerNames.nextElement();  
 out.print("<tr><td>" + paramName + "</td>\n");  
    String paramValue = request.getHeader(paramName);  
 out.println("<td> " + paramValue + "</td></tr>\n");  
   }  
 %>  
 </table>  
 </center>  
 </body>  
 </html>  


No comments:

Post a Comment