Hi, I am having the doubt regarding the request-response flow. Suppose i send a request or type www.javaranch.com, where does the request go? It goes on the server at the javaranch.com,the server then finds the requested page and returns it to client.Now, the requested page will be an html page? On the server machine, how many components are there? where does the Servlet lie?? where does the Web container lie?? where does the actual form lie?? Servlet contains Java code,web container also is a java code,the GET request is an Html request requested by the user,then how does the servlet helps in sending the response??
I just want to know the complete request-response flow Can anyone give me the link where the image regarding the above flow?
On the server machine, there is a servlet container, that receives the request, sees which server resources you are talking about from the URL, loads the class, instantiates the servlet object, creates ServletConfig object to pass it to the init() method (called only once, suppose it is first request), now to process the request creates two objects HttpServletRequest and HttpServletResponse and passes them to the service method. Sevlet creates a new thread and new call state for each request is used. Now service method decides what type of client request is. If it is GET, doGet and if it is POST doPost() method of the servlet is called.
Response is sent back to the client using response client that goes back through the container. Before the response is sent, the content type of the response is set using setContentType(...) method that tells the client browser how to use that content.
The locations of servlet, the form and jsps are decided upon with web server you are using. for example, in Tomcat, there servlet class file should be placed inside youwebapplication/WEB-INF/classes...this is different in while using java web server. Tomcat uses declarative form to seek information about the storage of particular page/servlet requested.
If you are referring to Head frist servlets and jsp then the first 2 chapters will tell you the basic flow of a resquest/responses and components involved in client and server.