#Understanding the #HTTP #Protocol: "Protocol is a set of rules followed by two parties, who want to participate in communication". #Adv #Java #Servlet #programming #Tutorial #advance #java #tutorial
There are two types of protocols:
---------------------------------
1) Application level protocol:
Defines rules that are required to get communication between two software or software application.
Ex: HTTP, jdbc:odbc, rmi & etc....
2) Network level protocol:
Defines rules that are required to get communication between two physical computers.
Ex: TCP/IP.
Http defines set of rules to transfer hypertext between browser window & server or server and browser window. (Hypetext is: text with hyerlinks)
When browser generates http protocol request to web resource programs it contain multiple details as H2P2 details:
H - Http Request method (Get/post/-----)
H - Http Request headers (user-agent, accept, accept-language ......)
P - Path of the requested web-resource(1DateApp or test1)
P - Request params (sno=101, sname=yogesh)
Similarly when web-resource program sends http protocol based response to browser window through web server it contains multiple details as SCH details:
S - Http response status code (100 to 599)
C - Response content (The real web-page content)
H - Http response headers (Cotent type, contentLength, refresh, .......)
Diagram (H2P2 and SCH):
-------
http request structure: (Diagram )
----------------------
-Request body is generally request parameter value(nothing but form data of form/web page)
-Client generated "GET" methodology request can carry only limited amount of data along with the request (max of 256 KB)
-Client generated "POST" methodology based request can carry unlimited amount of data.
Http Request include headers which provide extra information about the request:
1) Example of HTTP 1.1 Request: GET /search?keywords=servlets+jsp HTTP/1.1
Accept: image/gif, image/jpg, /
Accept-Encoding: gzip
Connection: Keep-Alive
Cookie: userID=id456578
Host: www.somebookstore.com
Referer: http://www.sun.com/xyz.html
User-Agent: Mozilla/4.7 [en] (Win98; U)
Accept-Indicates MIME types browser can handle
Accept-Encoding- Indicates encoding (eg. gzip or compress) browser can handle.
Authorization: User identification for password - protected pages.
Instead of HTTP authorization, use HTML forms to send username/password and store info in session object.
Connection: In HTTP 1.1, persistent connection is default.
Servlets should set Content-Length with setContentLength(use ByteArrayOutputStream to determine the length of output) to support persistent connections.
Cookie: Gives cookies sent to client by server sometime earlier. Use getCookies, not getHeader.
Host: Indicates host given in original URL
This is required in HTTP 1.1
If-Modified-Since: Indicates client wants page only if it has been changed after specified date.
Dont handle this situation directly; implement getLastModified instead.
Referer : URL of referring web page
Useful of tracking traffic, logged by many servers.
User-agent: String identifying the browser making the request.
Use with extreme caution!
Q What is the difference between request parameters & request headers:
----------------------------------------------------------------------
Request Parameter Request header
-------------------------------- ------------------------------------
1)End user supplied inputs to web 1) Browser supplied inputs to web
resource(form data) resource.
2)names & values are user defined 2) Header names are fixed & values
(eg: uname , pwd....) are browser specific.
3) Allows duplicate request param 3) Header names are unique.
name
4)Request Parameter Optional in 4) Request header names are mandatory
request. & implicit in request.
5) We can use either ServletRequest 5) We need HttpServletRequest object
object or HttpServeltRequest object to read request header values through
to read requst param values through servlet program.
servlet program.