While reading about servlet life cycle in a book, i came across this: Only a single instance of each servlet gets created with each user request resulting in a new thread that is handed off to doGet or doPost as appropriate. I understand everything except the servlet being instantiated, can someone tell me what it means?
Pretty much what it says. If I have a servlet in an app server then, even if there are 1000 users accessing the servlet at one time, only one instance is ever created - like with a new() statement.
All of the user requests are handled by a thread for that user. This is why it is very important to make sure that any data within a servlet is thread safe even though you never create or manage any threads.
<a href="http://forums.hotjoe.com/forums/list.page" target="_blank" rel="nofollow">Java forums using Java software</a> - Come and help get them started.
I'm quite new in J2EE and I still missing a fundamental step: is it better process the data received by the request directly in the servlet or in class instanced?
trying to decode a woman mind....
Joined: Sep 23, 2004
I'm not quite following you. In a HttpServlet has methods that are separated by HTTP method - a doPost() for HTTP POST requests, a doGet() for HTTP GET requests and so on.
As far as where you pull the data out of the HttpServletRequest that is really up to you. Back in the "old days" I just did it in the doGet()/doPost() methods by hand using getParameter() (which I can't link to because of the prehistoric age of the software running Javaranch ). Newer applications may benefit from using something like Java server faces or Struts. A part of these technologies is to make HTML form processing much easier.
Originally posted by Scott Dunbar: A part of these technologies is to make HTML form processing much easier.
You'll get differing opinions on that. There are those that would say that these technologies are just obfuscating factors that actually make things more difficult to accomplish under the guise of being "modern".