I am trying to understand how the apache web server works.I read in the head first servlets and JSP and the apache contains a container called tomcat and that the tomcat is a java program that calls the servlets.I also know that the apache also can server php pages.Is there a seperate container for apache that is resposible for handling php requests.And how does the apache server distinguish between requests that come for php and requests that come for jsp and servlets.
PHP is handled by native code within the apache web server (or, it can be). Servlets need be be handled by a servlet container running under a Java virtual machine.
These days it is common for people to use Tomcat as a standalone server for their web applications. It is also a fully functional web server. It's still possible to connect it to the apache webserver. To do so involves some bridge programs called 'connectors'. In the config files for these connectors, you would set up url-mappings for resources that you want handed from the Apache webserver to Tomcat.