It'd have been very useful for you had you first learned and understood the basics of Java ( language) before delving yourself into more advanced topics.
Anyway, the reason you are getting this error is because the Java compiler ( javac ) cannot find the JAR files containing the class files for the packages that you have mentioned. Now there are two solutions to this problem:
1. Every Servlet container makes available a JAR file which contains these packages e.g. J2EE 1.3.1 reference implementation contains these packages inside a JAR file called 'j2ee.jar' present in the 'lib' folder.
To know what JAR file of your Servlet container contains these packages, either check the documentation or look for similarly named JAR files in it's 'lib' folder.
Suppose you searched and find out that there is a 'j2ee.jar' JAR file in C:\SomeFoler\lib\ folder. To let the javac know about it you'll have to issue a command like this *every time* you want to compile this Servlet:
javac -classpath %CLASSPATH%;C:\SomeFoler\lib\j2ee.jar;. TestServlet.java
Where 'TestServlet.java' is the name of your TestServlet's source file. It'll compile the TestServlet.java source file into TestServlet.class file in the same folder.
2. Use a Servlet container like Resin ( www.caucho.com ), to develop applications. In Resin for example all you'll have to do is to place your .java source files of your Servlets, JavaBeans etc under the /WEB-INF/classes/ folder and when you access them the first time, Resin will automatically compile them for you.
When you make any changes in those source files, Resin will detect the changes and recompile them for you. It is just so helpful and will save you lot of time.
Btw I am not sure if it is possible with Tomcat, I haven't been using Tomcat lately so don't know.