Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet flow

 
Pankaj Shet
Ranch Hand
Posts: 289
Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?


Thank you.
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pankaj,

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.


Hope this much detail render some concepts.


Thanks,
 
Atul Sawant
Ranch Hand
Posts: 304
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pankaj,

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.
 
Pankaj Shet
Ranch Hand
Posts: 289
Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
-thanks for the reply.i read ist chapter and half the second one , I understood the flow,thanks..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic