Free servlet jsp tutorials
Its a very common question that many beginners ask "How to compile a servlet". This is because you need special jars in your classpath to compile a servlet.
Servlets are just like other simple java class but it has dependency on javax.servlet and javax.servlet.http packages.
This packages are part of servlet-api.jar file. servlet-api.jar file comes bundled with the servlet container or you can saperately download it from here.
If you are using Apache tomcat webcontainer, you can find the servlet-api.jar file under common/lib folder.
Now servlet class can be compiled just like other simple java class file using javac command.
javac MyFirstServlet.java
For more information on how to set the developement environment read Setting up the developement environmet.