Component Based Development/Basics

There are 2 conceptual models that give context to http and tcp/ip. The 4 layer model, puts http in the 4th application layer, tcp in the 3rd transport layer, ip in the 2nd internet layer. The 1st layer is often called the combined link/physical layer, and may consist of MAC/ethernet and DSL for example.

In an alternative model, the OSI 7 layer model, 1st layer is physical ,e.g DSL ; 2nd layer is data link e.g. MAC; 3rd layer is internet, e.g. IPV4/IPV6/IPSEC/UDP , except for ipsec, maybe connectionless ; 4th layer is transport , often connection/oriented e.g. TCP ; 5th layer is Session , which is space and time synchronized ( connection and session) , e.g. PAP/CHAP, the S in https ; 6th layer is Presentation, and may have encryption classified her, but conceptually might include html ; the 7th layer is the application layer, and often https, along with sftp, ftp, telnet, ssh, IMAP, SMTP are lumped at this level. Html might be classified 6b/7b , as it involves presentation and often is a application level protocol nowadays.

In the context of java web programming, java web containers such as Apache Tomcat provide the framework for API implementation of javax.servlet(.http). A javax.servlet.Servlet interface describes the GenericServlet abstract class and the HttpServlet abstract class, and application programmers are meant to use inheritance to create a subclass of GenericServlet or HttpServlet to fulfil their application writing wishes. The main abstract methods to implement by programmers are

 service(ServiceRequest req, ServiceResponse resp)

in GenericServlet , and

 doGet(HttpServiceRequest req, HttpServiceResponse resp)
 doPost(HttpServiceRequest req, HttpServiceResponse resp)

in HttpServlet.

The HttpServiceRequest inherits from ServiceRequest which has a getInputStream() and getReader() method, which allows reading of a user request. HTTPServiceRequest also has getCookies() and getQueryString() , getUri() and getParts() to get client web browser data for processing. This allows applications to do things like tracking the client without his/her knowledge but within legal boundaries that apply to traditional advertising mailing (we hope). It is also essential for processing legally agreed and implicitly consented form data that was entered by a user in the web page's form, as getQueryString() returns the & separated form elements.

HttpServieResponse has a getOutputStream() and getWriter() method for writing a response, for example, a html page. It also allows setting Http level information, which instruct the client's web browser to do something, such as set cookies, read response headers, redirect to another page, show an error code and message, in methods such as:

 addCookie(Cookie c)
 addHeader ( String name, String val)
 sendRedirect( String url )
 sendError( int errorCode, String msg)

This allows programming dynamic html at the lowest level of html application on a Web Container such as Tomcat.