Servlets are written according to the Servlet specification. This specification outlines what a Servlet can do, how a Servlet should behave, and how programmers can write code to develop servlets.
Programmers write Servlets according to the Servlet API, with an expectation of how a Servlet will behave at deployment time. When a Servlet is deployed to an applicaiton Server, like WebSphere or WebLogic, the vendor ensures that the deployed servlet behaves as a developer would expect it.
Here's a little link that describes Servlets and the J2EE server at runtime: