• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpServlet Request and Response objects creation

 
Naveen Kumar Kumar
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey there!!!

my first query on java ranch...this is absolutely a great forum..and wish i will be having a great learning time..

Q: My query is , I wanted to know how, when and where the HttpServletRequest and HttpServletResponse objects are created and sent as input arguments to the doGet() method in a servlet.

PS: Please forgive me if this has been already answered. Would be grateful if you can share me the link for that thread.

Thanks a lot in advance...

cheers...!!!

 
Fiorenza Oppici
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

If I studied well, these objects are created by the server container everytime a client sends a request. then if the servlet has already been initialised, the container creates the two objects HttpRequest and HttpResponse along with a specific thread (one per request) and then passes their reference to the servlet that corresponds to the client-requested URL.
hope I've been clear.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"practicalhead bean", please check your private messages for an important administrative matter. Thanks.
 
Naveen Kumar Kumar
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Fio..this has helped me correct my basic understanding ..

However, I would rather want a little detailed explanation through some sample code, like what actually happens when a user clicks on Go button in a browser, after the URL is decoded into host name, port no, specific file requested for. Also wanted to know what happens when servlet initialization is for the first time...

Thanks again...cheers....
 
Fiorenza Oppici
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this may help you understand better.
Head First JSP and servlets
serch for page 42, there's an useful diagram which shows you the lifecycle of request and responses.
I'm studying on this book and I recommend it to you if you want to learn and keep in mind how servlets actually work.


 
Naveen Kumar Kumar
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay thanks....let me check it...

cheers!!
 
Fiorenza Oppici
Ranch Hand
Posts: 38
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry I seen only now your last post, I'm not such an expert with code
but, as long as I know:
ServerInitialisation:
Before intialisation, a servlet is just a plain java object. then the container calls the method init() on it and it becomes a servlet, that means that it can handle client requests via the Service() method. the method init() is dependent from ServletConfig and ServletContext, two sets of information that can be set in a xml file called DD, deployment descriptor.
ServletConfig is a set of infos only for a specific servlet, ServletContext is visible from all the app (as long it's not distributed), and they are read only once in the lifecycle of a servlet. if you change some values you'll have to redeploy the servlet.

Client-side
the user types an url, usually basing on the HTTP protocol. the well-known port for HTTP is 80 from the client. (there's a lot of other stuff regarding socket initialisation and port allocation by server side in between I've learned in a previous long-time ago exam I'm not sure I could explain correctly). then http unwraps the HHTP request from all the lower level protocols encapsulation and retrieves the methods (Post ,Head, Get, whatever) and the URL requested. when a server receives a new Http request, it searches for the url in the dd.
in the dd there are tags which map the user-known name (contained into the url) to the middle name and other tags that map the middle name to the real pathname of the requested document as it's on the server, so you can set a correspondance.



This is all I know about that.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic