Hey, Naveen
Yes, that is quite a confusion... Here's how it goes:
init() is inovoked by the container (where your web app is running). The init method of the context is invoked when the web app starts, or when the first request for a resource on your web app is made (depending on how the people who developed the container felt like implementing it). As for a servlet init, it is invoked when the servlet is instantiated, which could be when the context is started up, or when the first request for your servlet comes through (you can configure this in the deployment descriptor).
SingleThreaded model has been deprecated in the latest Servlet spec, but if you're not using the lates spec, and you need to implement some thread safety mechanism, I recommend some reading as implementing the SingleThreaded model is basically the same as synchronizing the Service method. Instance variables, Session and Context attributes are still not thread safe.
the container creates 1 instance of your servlet, when it does that, it will call the init method then and only then. And for every request, depending on container implementation, a thread object will be created which at some poing will call the Service method on that 1 instance of your servlet. When you implement singlethreadedmodel, all you are doing is saying "If another thread wants to run my service method while I'm running it for someone else, it'll just have to wait til I'm done"
2) the session ID is typically implemented as a unique ID in a cookie called jsessionID. When a user has cookies disabled in his browser, then he can't make use of whatever functionality was implemented using sessions UNLESS the web app developer took the previsions of URL rewriting.
URL rewriting simply appends the jsessionID as part of a request attribute if and only if the requesting user's browser has cookies enabled. So now a request for
http://www.mysite.com/myapp/mypage.jsp
would look like this:
http://www.mysite.com/myapp/mypage.j...ssionid=123456
the way you us it is calling the encode methods on your URL, which in jsp would be done like this:
<a href="<%=response.encodeURL("http://www.mysite.com/myapp/mypage.jsp") %>"/>
To score a couple of brownie points with WROX, they have a very good book that covers this topic and much more ;)
Hope this helps
thanks